Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How to trap EXIT like in bash
- X-seq: zsh-users 20081
- From: Philippe Troin <phil@xxxxxxxx>
- To: Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx>
- Subject: Re: How to trap EXIT like in bash
- Date: Sat, 04 Apr 2015 10:08:34 -0700
- Cc: zsh-users@xxxxxxx
- In-reply-to: <mfovfc$g3$1@ger.gmane.org>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <mfovfc$g3$1@ger.gmane.org>
On Sat, 2015-04-04 at 17:20 +0200, Thorsten Kampe wrote:
> in Bash `trap "echo trapped" EXIT` will trigger when the script
> terminates normally and on SIGINT, SIGTERM, and SIGHUP.
>
> In Zsh, `trap "echo trapped" EXIT` triggers only on normal exit, but
> `trap "echo trapped" EXIT INT` will actually trigger twice on Ctrl-C.
>
> How can I trap normal exit, Ctrl-C, SIGTERM and SIGHUP so trap
> function will only run once?
I use this:
trap "echo trapped; exit 0" EXIT INT
That does the trick. Both bash and zsh print trapped only once.
I have no idea why zsh is incompatible with bash there, but this
behavior has been in zsh for quite a while.
Phil.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author