Joel Joel - 1 year ago 111
Linux Question

bash: command works in terminal, not in script

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
chmod +x

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}

Answer Source


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

Why doublequotes?

See [ this ] answer + [ this ] answer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download