Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
How to trap to script EXIT instead of function EXIT?
- X-seq: zsh-users 23782
- From: Peng Yu <pengyu.ut@xxxxxxxxx>
- To: zsh-users <zsh-users@xxxxxxx>
- Subject: How to trap to script EXIT instead of function EXIT?
- Date: Sun, 2 Dec 2018 22:09:37 -0600
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=LoVNCyIW8AijDkZieT1rRyzyKj6LMe4SdVtkWI03ZWI=; b=VSKmRYmuKOdo9sjvOHMyqRxikqSOvyDoSO4RFOpBKlq2a3MMg9t9hS4Zh3R7L+mwhv TEBlUH2aky4i/JiMJTBB8NGwkWlXeKi5U/6qmydL7KNg8w8MOl5oDsaJDSPXhlNFB5xS RCq/CBUKodv1z/OhYP4gUoV3GFIkVQJcaZ6BKJzgjxMGBt5ci+mj/h7jisfOtqz3Y4Af zoxoadY0ubOwaM3G/x9KkRwjsS62Xs45IFA5m6vqmpaeJY8+zHBKXdS9MTFqZ/lOMiUb 09xxFc/wfpbnYjJL23d5ABym5H3RU9Vkr6lVGQzUUQhqYUzyFrLHTe8eZ9k5orCzXmKK eGPw==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author