From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26269 invoked by alias); 4 Apr 2015 17:16:07 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20081 Received: (qmail 26325 invoked from network); 4 Apr 2015 17:16:05 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.2 Message-ID: <1428167314.5875.2.camel@niobium.home.fifi.org> Subject: Re: How to trap EXIT like in bash From: Philippe Troin To: Thorsten Kampe Cc: zsh-users@zsh.org Date: Sat, 04 Apr 2015 10:08:34 -0700 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4 (3.10.4-4.fc20) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit 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.