subshell exit trap -- 'echo exiting' EXIT trap -- 'echo aborting' SIGHUP trap -- 'echo aborting' SIGINT trap -- 'echo aborting' SIGQUIT trap -- 'echo aborting' SIGABRT trap -- 'echo aborting' SIGTERM [35] debug debug line [37] debug trap -- 'echo exiting' EXIT trap -- 'echo aborting' SIGHUP trap -- 'echo aborting' SIGINT trap -- 'echo aborting' SIGQUIT trap -- 'echo aborting' SIGABRT trap -- 'echo aborting' SIGTERM trap -- 'echo [$LINENO] debug' DEBUG [39] debug func[31] funcdebug funcdebug line ./trap.tests[41] funcdebug trap -- 'echo exiting' EXIT trap -- 'echo aborting' SIGHUP trap -- 'echo aborting' SIGINT trap -- 'echo aborting' SIGQUIT trap -- 'echo aborting' SIGABRT trap -- 'echo aborting' SIGTERM trap -- 'echo ${FUNCNAME:-$0}[$LINENO] funcdebug' DEBUG ./trap.tests[43] funcdebug ./trap.tests[48] debug ./trap.tests[49] debug func2[45] debug func2[46] debug func2debug line ./trap.tests[51] debug ./trap.tests[53] debug trap -- 'echo exiting' EXIT trap -- 'echo aborting' SIGHUP trap -- 'echo aborting' SIGINT trap -- 'echo aborting' SIGQUIT trap -- 'echo aborting' SIGABRT trap -- 'echo aborting' SIGTERM trap -- '' DEBUG trap -- 'echo exiting' EXIT trap -- 'echo aborting' SIGHUP trap -- 'echo aborting' SIGINT trap -- 'echo aborting' SIGQUIT trap -- 'echo aborting' SIGABRT trap -- 'echo aborting' SIGTERM trap -- 'echo exiting' EXIT trap -- '' SIGINT trap -- 'echo aborting' SIGQUIT trap -- 'echo aborting' SIGABRT trap -- 'echo aborting' SIGTERM 0 trap1.sub trap -- '' SIGUSR2 trap2.sub ERRTRAP ERRTRAP ERRTRAP after falses if negation ok after negation after while before false in trap2a.sub after false in trap2a.sub command substitution ERRTRAP ERRTRAP bar ERRTRAP ERRTRAP ERRTRAP ERRTRAP ERRTRAP trap3.sub +[6] echo 1 1 +[7] echo 2 2 +[8] false +[8] false +[8] false ++[8] echo trap: 8 trap: 8 +[9] echo 4 4 trap4.sub exit subshell 1 current shell exit subshell 2 current shell current shell current shell outside 1 outside 2 outside 3 outside 4 sleep 2 wait $! exit in trap EXIT sleep 2 wait $! exit in trap EXIT trap6.sub fn after 1 fn after 2 declare -- baz=$'bar\nfoo' trap7.sub trap8.sub before after CHLD CHLD CHLD CHLD trap9.sub BASH_TRAPSIG = USR1 func=7 222 exit=0 exit=0 A In trap-argument: last command preceding the trap action In a function call: last command in the trap action trap10.sub ERR: 23: -func- failed ERR: 20: -[[ -z nonempty ]]- failed ERR: 27: -func- failed ERR: 35: -func2- failed ERR: 39: -func2- failed caught a child death caught a child death caught a child death trap -- 'echo caught a child death' SIGCHLD echo caught a child death ./trap.tests: line 125: trap: cannot specify both -p and -P ./trap.tests: line 126: trap: -P requires at least one signal name trap: usage: trap [-Plp] [[action] signal_spec ...] ./trap.tests: line 128: trap: -x: invalid option trap: usage: trap [-Plp] [[action] signal_spec ...] trap -- 'echo exiting' EXIT trap -- 'echo aborting' SIGABRT trap -- 'echo caught a child death' SIGCHLD trap: usage: trap [-Plp] [[action] signal_spec ...] echo exiting exiting