The EXIT trap does not work the same in every shell. A few examples:
- In dash and zsh, it only starts by regularly exiting the script.
- In zsh, if you catch a signal that normally stops executing, you need to restore the default behavior by explicitly calling
exit
.
I would advise you to actually catch the signals and then exit, it should be portable in most shells:
$ cat trap trap 'echo exit; exit' INT TERM
source share