From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27192 invoked by alias); 9 Sep 2010 09:34:40 -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: 15376 Received: (qmail 17045 invoked from network); 9 Sep 2010 09:34:34 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Thu, 9 Sep 2010 09:57:53 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: trap does not work in a trap function? Message-ID: <20100909095753.5473e833@pwslap01u.europe.root.pri> In-Reply-To: <20100909081733.76300@gmx.net> References: <20100909080214.76320@gmx.net> <20100909081733.76300@gmx.net> Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.6 (GTK+ 2.18.9; i686-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 09 Sep 2010 08:57:55.0133 (UTC) FILETIME=[1797B6D0:01CB4FFD] X-Scanned-By: MailControl A-10-90-03 (www.mailcontrol.com) on 10.68.0.149 On Thu, 09 Sep 2010 10:17:33 +0200 "Dominik Vogt" wrote: > shutdown () { > echo shutdown > trap - EXIT > exit 77 > } >=20 > trap shutdown EXIT > shutdown > -- END sigtest >=20 > > $ ./sigtest > > shutdown > > shutdown > >=20 > > Why is the shutdown function called again by exit when the EXIT > > trap was just removed? This looks like the trap builtin does not > > properly work from within a trap handler. The EXIT trap you removed was the one for the "shutdown" function. In zsh, EXIT is used with functions as well as scripts. You can do what you want like this: shutdown () { echo shutdown trap 'trap - EXIT' EXIT exit 77 } unless shutdown is itself called from within a function, in which case you're removing the EXIT trap for that. =46rom the documentation for the "trap" builtin: If sig is 0 or EXIT and the trap statement is executed inside the body of a function, then the command arg is executed after the function completes. The value of $? at the start of execu- tion is the exit status of the shell or the return status of the function exiting. If sig is 0 or EXIT and the trap statement is not executed inside the body of a function, then the command arg is executed when the shell terminates. --=20 Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, = UK Member of the CSR plc group of companies. CSR plc registered in England and= Wales, registered number 4187346, registered office Churchill House, Cambr= idge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom