2

I try to read the output of the bash command 'openssl help' and put it in a string variable for further processing.

To be precise I want to test all Cipher commands.

First I tried to read the output of the command 'openssl ciphers'. But I got only ciphers and not the cipher commands. But if I type 'openssl help' then the cipher commands are shown. The problem is that now the output of the command is not saved in my variable.

CIPHER=`openssl ciphers`
echo "Output:"
echo $CIPHER

This works. But unfortunately the content of $CIPHER is not what I need.

CIPHER=`openssl help`
echo "Output:"
echo $CIPHER

This doesnt work. The variable CIPHER is empty. Why??

1 Answers1

1

It does seem openssl help contents are written to the standard error stream stderr(2) instead of stdout(1). Suggest re-redirecting the error stream (represented by file descriptor 2) to standard output(represented by file descriptor 1) to fix the issue.

Since the output contains a multi-line stream, recommend enclosing the $(..) command-substitution over backticks (outdated technique) with proper double-quotes.

sslOutput="$(openssl help 2>&1)"
printf "%s\n" "${sslOutput}"

See why $(..) is prefereed over legacy .. syntax for command substitution.

Inian
  • 80,270
  • 14
  • 142
  • 161
  • Also see [Should the command line “usage” be printed on stdout or stderr?](https://stackoverflow.com/q/2199624/608639) – jww Jun 21 '17 at 21:57