From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1814 invoked by alias); 7 Apr 2015 07:54:33 -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: 20104 Received: (qmail 16872 invoked from network); 7 Apr 2015 07:54:31 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.2 Date: Tue, 7 Apr 2015 15:44:13 +0800 From: Han Pingtian To: zsh-users@zsh.org Subject: Re: How to trap EXIT like in bash Message-ID: <20150407074413.GH2805@localhost.localdomain> Mail-Followup-To: zsh-users@zsh.org References: <150404113557.ZM14788@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <150404113557.ZM14788@torch.brasslantern.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15040707-0021-0000-0000-000009A8C1A6 On Sat, Apr 04, 2015 at 11:35:57AM -0700, Bart Schaefer wrote: > Hmm. This seems to be a side-effect of the rule that the EXIT trap does > not run from inside other traps. The default response to INT in a script > is to behave as if 'trap "exit 130" INT' so the EXIT trap is not run. In > > Curiously in an interactive shell, the following prints "trapped" exactly > one time, even though my first answer above also works interactively: > > trap "echo trapped" EXIT > trap exit HUP INT TERM > > However, that does not work in a script. I'm not sure why interactive > matters here. I think because the rule that EXIT trap doesn't run from inside other traps, the phenomenon of script not working is correct and the interactive shell working is wrong. Am I right?