zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@sunsite.auc.dk (Zsh list)
Subject: Re: TRAPEXIT question
Date: Wed, 04 Aug 1999 09:47:31 +0200	[thread overview]
Message-ID: <9908040747.AA12481@ibmth.df.unipi.it> (raw)
In-Reply-To: ""Bart Schaefer""'s message of "Wed, 04 Aug 1999 04:40:26 DFT." <990804044026.ZM12690@candle.brasslantern.com>

"Bart Schaefer" wrote:
> This has an interesting side-effect in the case of the EXIT trap.  If you
> use the `TRAPEXIT() { ... }' function form, then other traps set within the
> trap itself have the context of the TRAPEXIT function; but if you use the
> `trap "..." EXIT' form, traps set within the trap have as their context a
> function that has already exited -- and as a consequence they get set in
> the next context up, which can even be the top-level shell.
> 
> (I don't know if any other shell behaves this way; I know bash does *not*.
> The new LOCAL_TRAPS option in 3.1.6 doesn't appear to affect it.)

ksh works this way, as far as the trap builtin is concerned, which is why
zsh does.  bash doesn't seem to regard EXIT traps as applying to functions
at all.  Neither of them have TRAP functions, which were presumably
introduced to avoid the messy quoting syntax, although as you pointed out
you can have the real function defined somewhere else (but then you still
lose the effect of being in the surrounding context).  In the early days
zsh called them both with a separate function environment, and this is
different from any other shell; only the trap builtin was fixed, however,
since if you define a function trap it's natural that it should have a
function environment.

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


  reply	other threads:[~1999-08-04  8:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-03 18:50 Greg Klanderman
1999-08-04  4:40 ` Bart Schaefer
1999-08-04  7:47   ` Peter Stephenson [this message]
1999-08-04 21:54   ` Greg Klanderman
1999-08-05  8:34     ` Peter Stephenson
1999-08-05 10:51       ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9908040747.AA12481@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).