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

Re: local variable assignment and pipelines?

Dan Nelson wrote:
> a=1 | echo $a      -> prints "1" on zsh, prints nothing on ash,pdksh,bash

It's an inevitable but unintended side effect of the way some
substitutions are done by the shell before it forks.  The list given in
subst.c is this one.

/* Do substitutions before fork. These are:
 *  - Process substitution: <(...), >(...), =(...)
 *  - Parameter substitution
 *  - Command substitution
 * Followed by
 *  - Quote removal
 *  - Brace expansion
 *  - Tilde and equals substitution

My guess is this is left undefined by POSIX etc.  The stuff on pipelines
is fairly terse, but there might be something elsewhere since I didn't
look all that closely.

Where you would not want this to happen, and it doesn't, is if the
assignment immediately precedes a command.


The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
If you received this in error, please contact the sender and 
delete the material from any computer.

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