1

I am doing

a="$(openssl x509 -in /path/to/pemfile.pem -text -noout)";
echo ${a} |grep -a1 -b2 Signature

which works quite well if i put this line into terminal

However, if i put the very same line in a file executeme.sh, chmod +x executeme.sh, ./executeme.sh

I seems does not create the linebreaks in the variable, resulting grep to receive just one line. output is as follows on the terminal:

20- Version: 3 (0x2)
38- Serial Number: 32 (0x27)
64: Signature Algorithm: md5WithRSAEncryption
107- Issuer: C=EN, ST=a, L=b, O=c, OU=d, CN=e
244- Validity
------
[...]

The script outputs the entire certificate , as if i would only do a="$(openssl ...)"; echo ${a}

sjsam
  • 21,411
  • 5
  • 55
  • 102
Joel
  • 1,725
  • 3
  • 16
  • 34

1 Answers1

2

Do

echo "${a}" |grep -a1 -b2 Signature #mind the double quotes

Why doublequotes?

See [ this ] answer + [ this ] answer.

Community
  • 1
  • 1
sjsam
  • 21,411
  • 5
  • 55
  • 102
  • @Joel : Thanks for accepting, Do have a look at the links, especially the second one. – sjsam Jul 20 '16 at 06:32
  • I understand, that it is working. `echo` seems to output as shot as possible - right? Apperently, I can avoid it, forcing the specified String (${a}) to be seen as a whole string. – Joel Jul 20 '16 at 06:34
  • 1
    @Joel : Kinda. Double quotes prevents squeezing of space characters which include whitespace, tabs and linefeeds and so. – sjsam Jul 20 '16 at 06:37