# error-p.sh: test of error conditions for any POSIX-compliant shell posix="true" test_O -d -e n 'syntax error kills non-interactive shell' fi echo not reached __IN__ test_O -d -e n 'syntax error in eval kills non-interactive shell' eval fi echo not reached __IN__ test_o -d 'syntax error in subshell' (eval fi; echo not reached) [ $? -ne 0 ] echo $? __IN__ 0 __OUT__ test_o -d 'syntax error spares interactive shell' -i +m fi echo reached __IN__ reached __OUT__ test_O -d -e n 'expansion error kills non-interactive shell' unset a echo ${a?} echo not reached __IN__ test_o -d 'expansion error in subshell' unset a (echo ${a?}; echo not reached) [ $? -ne 0 ] echo $? __IN__ 0 __OUT__ test_o -d 'expansion error spares interactive shell' -i +m unset a echo ${a?} [ $? -ne 0 ] echo $? __IN__ 0 __OUT__ test_O -d -e 127 'command not found' ./_no_such_command_ __IN__ ############################################################################### test_O 'assignment error without command kills non-interactive shell' readonly a=a a=b printf 'not reached\n' __IN__ test_o 'assignment error without command in subshell' readonly a=a (a=b; printf 'not reached\n') [ $? -ne 0 ] echo $? __IN__ 0 __OUT__ test_o 'assignment error without command spares interactive shell' -i +m readonly a=a a=b printf 'reached\n' __IN__ reached __OUT__ # $1 = line no. # $2 = command name test_assign() { testcase "$1" -d \ "assignment error on command $2 kills non-interactive shell" \ 3<<__IN__ 4