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

exit does not exit in traps triggered within functions



Hello,

Users at Unix.StackExchange suggested that I forward a question of
mine appearing here [1], as a potential bug.

Consider these two examples, the second contributed by Stéphane Chazelas:

$ zsh -c 'trap "exit 1; echo X" TERM; f() { kill -TERM $$; echo Y; }; f'
Y
$ zsh -c 'trap "exit 1; echo X" EXIT; f() { exit;          echo Y; }; f'
X

In the first case, the exit in the trap causes the trap to end, but
f() continues executing—but does not return.  The return value of the
program is 1.

In the second case, the exit in the trap does not cause the trap to
end immediately, the trap finishes and does not return, and the return
value of the program is 0.

As far as I understand, the expected behavior, which BASH displays, is
for these two scripts to print nothing.

Tested on zsh 5.5.1 and 5.8.

Thanks.

1: https://unix.stackexchange.com/questions/616217/why-does-zsh-finish-executing-a-function-after-exit-was-called-from-a-trap




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