zsh-users
 help / color / mirror / code / Atom feed
* How to trap to script EXIT instead of function EXIT?
@ 2018-12-03  4:09 Peng Yu
  2018-12-03  7:41 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peng Yu @ 2018-12-03  4:09 UTC (permalink / raw)
  To: zsh-users

Hi,

The following example shows that `trap` inside a function is trapped
to the function. This behavior is different from bash. Is there a way
to make it the same as bash?

$ cat main.sh
#!/usr/bin/env zsh
# vim: set noexpandtab tabstop=2:

set -v
function f {
	trap "echo 'Hello World!'" EXIT
	trap
}
f
trap
$ ./main.sh
function f {
	trap "echo 'Hello World!'" EXIT
	trap
}
f
trap -- 'echo '\''Hello World!'\' EXIT
Hello World!
trap

$ cat ./main.bash
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

set -v
function f {
	trap "echo 'Hello World!'" EXIT
	trap
}
f
trap
$  ./main.bash
function f {
	trap "echo 'Hello World!'" EXIT
	trap
}
f
trap -- 'echo '\''Hello World!'\''' EXIT
trap
trap -- 'echo '\''Hello World!'\''' EXIT
echo 'Hello World!'
Hello World!

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-12-03 15:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-03  4:09 How to trap to script EXIT instead of function EXIT? Peng Yu
2018-12-03  7:41 ` Bart Schaefer
2018-12-03 14:05   ` Peng Yu
2018-12-03 14:59     ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).