Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: EXIT trap executes too late?Re: stuff



Bart wrote:
> "The functions beginning `TRAP' may alternatively be defined with the
> trap builtin:  this may be preferable for some uses, as they are then
> run in the environment of the calling process, rather than in their own
> function environment."
> 
> That doesn't appear to be true for the EXIT trap:

You're missing this (second paragraph of the texinfo node Functions):

  Functions execute in the same process as the caller and share all files
  and present working directory with the caller.  A trap on EXIT set
  inside a function is executed after the function completes in the
  environment of the caller.

So `the environment of the calling process' in the first quotation is
the environment which called the function for which the exit trap is
set, not the function where the exit trap is defined.  So it's doing
it's job properly (and indeed it was to ensure this behaviour that I
tinkered with execsave()/execrestore()).  However, this is confusing
because of the way `environment of the caller' has two meanings and the
documentation could probably be clearer.

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
Work: pws@xxxxxxx
Web: http://www.pwstephenson.fsnet.co.uk



Messages sorted by: Reverse Date, Date, Thread, Author