# The ERR trap runs after a command fails, where errexit would act. trap 'echo "ERR status=$?"' ERR false (exit 7) true false || echo "or: no trap" if false; then :; fi; echo "if: no trap" ! true; echo "not: no trap" false | true; echo "pipe ok: no trap" true | false f() { return 4; }; f x=$(false); echo "assign status=$?" trap trap - ERR false; echo "removed" trap 'echo first; false; echo "inside=$?"' ERR false trap 'echo e' ERR (false; echo "in subshell: reset") trap 'echo "then exit"' ERR set -e false echo not-reached