title: How to detect failure from OpenSSL in Bash
body: <p>It seems OpenSSL does not return exit codes when there is an error.  For example, ran is not an OpenSSL command (should be "rand"), but the shell result code is still set to zero.  Is there a way to change OpenSSL's behavior here (short of building a custom version)?</p>
  
  <p>For example, this print "ok", "ok", rather than "fail", "ok" as expected:</p>
  
  <pre><code>openssl ran 8
  if [ $? -eq 0 ]; then
     echo "ok"
  else
     echo "fail"
  fi
  openssl rand 8
  if [ $? -eq 0 ]; then
     echo "ok"
  else
     echo "fail"
  fi
  </code></pre>