Originally Posted by Don Cragun
Obviously, the commands specified by the action in a
trap action EXIT command won't be executed if the shell is terminated by a SIGKILL signal since the shell can't catch a SIGKILL to invoke the actions specified by appropriate traps.
True. This notable exception i have explicitly stated (in post #4, last line). It is because of the nature of this signal, which is not directed at the process but rather at the kernel. A process terminated by SIGKILL doesn't terminate itself, but rather is terminated by the kernel.
If the standard is interpreted as you expect, then no system conforms to the standard because the standard doesn't allow an exception for being terminated by SIGKILL.
Actually what i tried to get across was: save for SIGKILL, any other way of terminating
a script (simple end, send a SIGTERM via "kill -15", press "CTRL-C", ...) will result in trap 0 (EXIT) being executed - not just using the "exit" built-in.
This is in fact as it should be because a script terminated by "kill -9" probably best leaves its temporary files for further inspection (one wouldn't terminate a script this way without some serious reason) and all other methods of ending a script are covered.
Thanks for sharing your thoughts.