0

I searched for my problem on google and found following solution: How to concatenate string variables in Bash? would have been cool if it had been that easy, but apparently there must be an exception for my problem. I have a shell script with a variable which looks like following

#!/bin/bash
egrep "CN=$1/" index.txt|awk '{print $3}'
userpem="$3.pem"
openssl x509 -in $userpem -noout -text

unfortunately it just gives out .pem. Do you have any suggestions why this happens?

Community
  • 1
  • 1
BoJack Horseman
  • 4,406
  • 13
  • 38
  • 70

1 Answers1

1

it just gives out ".pem" why :( ?

Because $3 is interpreted as an argument that was passed to the script which is probably nothing.

You need to concatenate the output of the command you executed. Say:

userpem=$(egrep "CN=$1/" index.txt|awk '{print $3}').pem

instead. You might also want to refer to Command Substitution.

devnull
  • 118,548
  • 33
  • 236
  • 227