zsh-users
 help / color / mirror / code / Atom feed
* Strange parameter visibility
@ 2016-09-17 18:11 Kamil Jońca
  2016-09-18  1:42 ` Eric Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Kamil Jońca @ 2016-09-17 18:11 UTC (permalink / raw)
  To: zsh-users


--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

-- 
http://stopstopnop.pl/stop_stopnop.pl_o_nas.html
The rose of yore is but a name, mere names are left to us.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Strange parameter visibility
  2016-09-17 18:11 Strange parameter visibility Kamil Jońca
@ 2016-09-18  1:42 ` Eric Cook
  2016-09-18  4:37   ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Cook @ 2016-09-18  1:42 UTC (permalink / raw)
  To: zsh-users

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Strange parameter visibility
  2016-09-18  1:42 ` Eric Cook
@ 2016-09-18  4:37   ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2016-09-18  4:37 UTC (permalink / raw)
  To: Zsh Users

On Sat, Sep 17, 2016 at 6:42 PM, Eric Cook <llua@gmx.com> wrote:
>
> 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.

I have to conclude that's a bug -- it's OK to optimize out the fork,
but not to optimize out its side effects (or cause new ones).


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-18  4:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-17 18:11 Strange parameter visibility Kamil Jońca
2016-09-18  1:42 ` Eric Cook
2016-09-18  4:37   ` Bart Schaefer

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).