I have a simple script
trap 'echo exit' EXIT
while true; do sleep 1; done
and it behaves differently in different shells:
$ bash tst.sh
^Cexit
$ dash tst.sh
^C
$ zsh tst.sh
^C
$ sh tst.sh
^Cexit
So I'm not sure about how it should operate and whether it is specified at all.
EXIT
trap isn't working the same way in every shell. A few examples:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With