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

Re: Bug with trap?

On Mon, 3 May 2010 21:49:50 +0300
"Nadav Har'El" <nyh@xxxxxxxxxxxxxxxxxxx> wrote:
> On Fri, Apr 30, 2010, Omari Norman wrote about "Bug with trap?":
> > It seems that the trap builtin with the EXIT argument does not work
> > properly if you have a list inside curly braces and the output is piped
> > to another command. For example:
> >...
> > { trap "echo exit trap running" EXIT} | cat
> >...
> > Thus the trap in the last example simply did not run. You can try this
> > with another command in the trap (e.g. touch, or rm) and you will get
> > the same result: the trap does not run.
> > 
> > This is zsh 4.3.6 on Debian 5.0. Is this a bug or am I missing
> > something?
> This is not a bug, but rather a result of the way that shells (not just zsh)
> do pipes.

I was wondering along the lines you suggest, but the counterargument is
that if you do:

zsh -fc '{ trap "echo exit trap running" EXIT; exit} | cat'

you get the expected message when the left-hand-side (explicitly) exits.
It's not clear to me it should be different on an implicit exit.  Traps
are an area where bugs and features are particularly intertwined.  I may
get around to looking at what I think the code is doing.  (Any
suggestion of vagueness in that sentence is entirely intentional...)

Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/

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