# An error the shell catches (`command eval`) must leave no trace of the # command that failed: not its variables, not a redirection it had in force, # not the text it was reading. The state is put back before the jump, while # the frames that own it still exist. f() { x=1; echo "${u?boom}"; } command eval f >/dev/null 2>&1 echo "vars: [$x]" # f's stdout redirection must be undone with the error g() { echo "${u?boom}" >/dev/null; } command eval g 2>/dev/null echo "stdout is back" # the eval text is not read again h() { echo "${u?boom}"; } command eval 'h; echo not reached' 2>/dev/null echo "input is back" # and it still works after many such errors i=0 while [ $i -lt 50 ]; do command eval f >/dev/null 2>&1 i=$((i + 1)) done echo "survived $i"