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

Re: Strange parameter visibility



On 09/17/2016 02:11 PM, Kamil Jońca wrote:
> 
> --8<---------------cut here---------------start------------->8---
> %(x=1; x=2 echo | echo $x ; echo $x) 
> 1
> 1
> --8<---------------cut here---------------end--------------->8---
> 
> but :
> --8<---------------cut here---------------start------------->8---
> %(x=1; x=2 | echo $x ; echo $x) 
> 2
> 2
> --8<---------------cut here---------------end--------------->8---
> 
> What there are "2"-s in second example?
> should'n "x=2" be treated as simple null command with its own
> assignement?
> KJ
> 

It's a normal assignment just like the x=1. the weirdness is zsh
optimizing out a fork in the pipeline, so the scope of the
reassignment wasn't just a subshell.

Though, in the first example you put the variable into echo's
environment, the shell parameter x wasn't changed at all.



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