I've noticed that when Bash is called as sh
, you cannot unset a trap using e.g., trap -- EXIT
, but when it is called as bash
you can.
trap - EXIT
seems to work regardless of how the shell was called.
Example output:
[vagrant@localhost ~]$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Mar 9 2016 /bin/sh -> bash
[vagrant@localhost ~]$ sh
sh-4.1$ trap 'echo something' EXIT
sh-4.1$ exit
exit
something
[vagrant@localhost ~]$ sh
sh-4.1$ trap 'echo something' EXIT
sh-4.1$ trap -- EXIT
trap: usage: trap [-lp] [[arg] signal_spec ...]
sh-4.1$ trap - EXIT
sh-4.1$ exit
exit
[vagrant@localhost ~]$ bash
[vagrant@localhost ~]$ trap 'echo something' EXIT
[vagrant@localhost ~]$ exit
exit
something
[vagrant@localhost ~]$ bash
[vagrant@localhost ~]$ trap 'echo something' EXIT
[vagrant@localhost ~]$ trap -- EXIT
[vagrant@localhost ~]$ exit
exit
[vagrant@localhost ~]$ bash
[vagrant@localhost ~]$ trap 'echo something' EXIT
[vagrant@localhost ~]$ trap - EXIT
[vagrant@localhost ~]$ exit
exit
[vagrant@localhost ~]$
I checked the documentation but I don't see the difference elucidated anywhere. I do see that the single hyphen form is specified by POSIX.
Is there any difference in behavior between the two methods of unsetting a trap, other than --
not working in sh
?