shell - test for process return status returns unexpected results on ubuntu -


here's piece of shell script code executing on ubuntu machine:

myprocess ret="$?" if [  "${ret}" == "0" ]    echo else    echo bad "${ret}" fi 

so logic pretty simple: if myprocess returns non-zero exit status, it's bad, otherwise good. tested piece of code isolating separate script , running command line. when myprocess returned 0, got good expected.

however, when run in production, bad 0. though return code seems 0, if test seems return false. what's going on here?

it appears problem in use of many quotes possibly in combination ==. following modified code seems working fine:

myprocess ret=$? if [  ${ret} -eq 0 ]     echo else     echo bad "${ret}" fi 

Comments