Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

traps not reset in pipe component subshells



Hello,

$ zsh -c 'trap "print -u2 out" EXIT; exit | exit | exit'
out
out
out


That's the only case I could find where the traps are not reset
in a subshell (tried coproc, zpty, $(...), <(...), exit&)

Another POSIX non-conformance:

$ bash -c 'trap uname EXIT; echo "$(trap)"'
trap -- 'uname' EXIT
Linux
$ zsh -c 'trap uname EXIT; echo "$(trap)"'

Linux

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#trap

POSIX requires $(trap) be treated as a special case so one can do:

traps=$(trap)
...
eval "$traps" # restore earlier traps

dash and mksh have the same problem. In zsh, thanks to the
first /bug/ above, one can do:

trap | IFS= read -rd '' traps

It may make sense to have a $trap[NAL] zsh/parameter hash for
that (where an empty value means ignored, while "-" means
default, not sure what to do if there's a TRAPNAL() but an
application can always check $+functions[TRAPNAL] first).

See also:
https://unix.stackexchange.com/questions/343990/dash-how-to-capture-output-of-trap-invoked-w-o-arguments/343999#343999

-- 
Stephane



Messages sorted by: Reverse Date, Date, Thread, Author