Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[BUG] Sticky-sh POSIX_TRAPS are function-local
- X-seq: zsh-workers 37977
- From: Martijn Dekker <martijn@xxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [BUG] Sticky-sh POSIX_TRAPS are function-local
- Date: Mon, 15 Feb 2016 06:11:13 +0100
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
The POSIX_TRAPS option for the EXIT trap does not work if both of the
following conditions apply:
- zsh was launched as zsh, not sh
- the EXIT trap is set from a shell function with sticky sh emulation
Script showing the bug (on zsh-5.2-142-gac5d83b):
#! /bin/zsh
echo start program
emulate sh -c 'testfn() {
echo start function
set -o | grep posixtraps
trap "echo EXIT TRAP TRIGGERED" EXIT
echo end function
}'
testfn
echo program continuing
echo end of program
Actual output:
start program
start function
noposixtraps off
end function
EXIT TRAP TRIGGERED
program continuing
end of program
Expected output:
start program
start function
noposixtraps off
end function
program continuing
end of program
EXIT TRAP TRIGGERED
Note how the EXIT trap is triggered upon exit from the function that set
it, and not upon exit from the shell, even though 'emulate sh' should
activate POSIX_TRAPS so the function should have set a global trap.
Thanks,
- M.
(How I found this bug: my cross-platform shell library, modernish
<https://github.com/modernish/modernish>, can be used with native zsh
with the command
emulate sh -c '. modernish'
Sticky sh emulation is fantastic: the library's features mix in
seamlessly with native zsh, even the crazy alias-based ones such as the
new loop constructs. The only thing that is *not* working are the
functions that set EXIT traps, i.e.. 'pushtrap' -- stack-based traps, so
modernish modules can set their own clean-up traps without interfering
with others. On native zsh with modernish in sticky sh emulation, those
get executed instantly upon setting them.)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author