zsh-workers
 help / color / mirror / code / Atom feed
  • * Re: Strange parameter visibility
           [not found] ` <87bmzmtmzq.fsf@alfa.kjonca>
           [not found]   ` <831b307a-a00f-1df7-5136-17fcb769ccaf@gmx.com>
    @ 2016-09-29 16:24   ` Peter Stephenson
      2016-09-29 17:03     ` Peter Stephenson
      1 sibling, 1 reply; 9+ messages in thread
    From: Peter Stephenson @ 2016-09-29 16:24 UTC (permalink / raw)
      To: Zsh Hackers' List
    
    On Sat, 17 Sep 2016 20:11:37 +0200
    Kamil Jońca <kjonca@o2.pl> wrote:
    > --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?
    
    Try this.
    
    This isn't an optimisation gone awry --- we just plain miss out on
    checking that the LHS of the pipeline is supposed to run in the shell so
    we need to fork to do that, as we do in other cases.  It's obviously
    never come up because the assigment is redundant, or should be.
    
    We might be able to renumber the WC_ codes to make this more efficient.
    
    pws
    
    diff --git a/Src/exec.c b/Src/exec.c
    index c79a278..e3915dd 100644
    --- a/Src/exec.c
    +++ b/Src/exec.c
    @@ -1844,7 +1844,8 @@ execpline2(Estate state, wordcode pcode,
     	/* if we are doing "foo | bar" where foo is a current *
     	 * shell command, do foo in a subshell and do the     *
     	 * rest of the pipeline in the current shell.         */
    -	if (wc_code(code) >= WC_CURSH && (how & Z_SYNC)) {
    +	if ((wc_code(code) >= WC_CURSH || wc_code(code) == WC_ASSIGN)
    +	    && (how & Z_SYNC)) {
     	    int synch[2];
     	    struct timeval bgtime;
     
    diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
    index 921ff99..0b1085c 100644
    --- a/Test/A01grammar.ztst
    +++ b/Test/A01grammar.ztst
    @@ -756,3 +756,10 @@
     >	print Stuff here
     >}
     >Stuff here
    +
    +  x=1
    +  x=2 | echo $x
    +  echo $x
    +0:Assignment-only current shell commands in LHS of pipelin
    +>1
    +>1
    
    
    ^ permalink raw reply	[flat|nested] 9+ messages in thread

  • end of thread, other threads:[~2016-09-30 19:05 UTC | newest]
    
    Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
    -- links below jump to the message on this page --
         [not found] <CGME20160917181339eucas1p24d214aa618aa96b5a8ddfbf351598da6@eucas1p2.samsung.com>
         [not found] ` <87bmzmtmzq.fsf@alfa.kjonca>
         [not found]   ` <831b307a-a00f-1df7-5136-17fcb769ccaf@gmx.com>
         [not found]     ` <CAH+w=7YtacLo6aY9gT5V27xYbh-wz0Tot1kbPxBiWN1ZXpavRA@mail.gmail.com>
    2016-09-18  4:55       ` Strange parameter visibility Bart Schaefer
    2016-09-29 16:24   ` Peter Stephenson
    2016-09-29 17:03     ` Peter Stephenson
    2016-09-29 21:28       ` Bart Schaefer
    2016-09-29 21:36         ` Bart Schaefer
    2016-09-30  8:50         ` Peter Stephenson
    2016-09-30  9:36           ` Peter Stephenson
    2016-09-30 13:50             ` Peter Stephenson
    2016-09-30 19:06               ` 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).