# `command` takes away the special properties of special builtins: an # error inside them sets a status instead of exiting the shell. command eval 'if' 2>/dev/null echo "eval syntax: $?" command . ./nonexistent 2>/dev/null echo "dot missing: $?" printf 'if\n' >bad.sh command . ./bad.sh 2>/dev/null echo "dot syntax: $?" command eval 'x=$((1/0))' 2>/dev/null echo "eval arith: $?" f() { command eval 'return 3' echo not reached } f echo "return through command eval: $?" for i in 1 2; do command eval break echo "loop $i" done echo "after break" # errors caught many times leave the shell usable (no leaked state) i=0 while [ $i -lt 20 ]; do command eval 'if' 2>/dev/null command . ./bad.sh 2>/dev/null i=$((i + 1)) done echo "survived $i" x=$(command eval 'if' 2>/dev/null; echo "in cmdsub $?") echo "$x" (command eval 'exit 4'; echo not reached) echo "exit still exits: $?" # without command, the error exits the shell eval 'if' 2>/dev/null echo not reached