EXIT
trap isn't working the same way in every shell. A few examples:
- In dash and zsh it's only triggered by a regular exit from within the script.
- In zsh, if you trap a signal that would normally quit the execution, you need
to restore the default behaviour by explicitly calling
exit
.
I'd suggest you to actually catch the signals and then exit, it should be portable
across most shells:
$ cat trap
trap 'echo exit; exit' INT TERM # and other signals
while true; do sleep 1; done
$ bash trap
^Cexit
$ dash trap
^Cexit
$ zsh trap
^Cexit
$ ksh trap
^Cexit
$ mksh trap
^Cexit
$ busybox sh trap
^Cexit