From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28336 invoked from network); 6 Jan 2004 01:40:07 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 6 Jan 2004 01:40:07 -0000 Received: (qmail 23949 invoked by alias); 6 Jan 2004 01:39:41 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6984 Received: (qmail 23911 invoked from network); 6 Jan 2004 01:39:41 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 6 Jan 2004 01:39:41 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [35.9.66.29] by sunsite.dk (MessageWall 1.0.8) with SMTP; 6 Jan 2004 1:39:40 -0000 Received: from valentino.pa.msu.edu (localhost.localdomain [127.0.0.1]) by valentino.pa.msu.edu (8.12.8/8.12.8) with ESMTP id i061dddB011405 for ; Mon, 5 Jan 2004 20:39:39 -0500 Received: (from juhas@localhost) by valentino.pa.msu.edu (8.12.8/8.12.8/Submit) id i061dduG011403 for zsh-users@sunsite.dk; Mon, 5 Jan 2004 20:39:39 -0500 X-Authentication-Warning: valentino.pa.msu.edu: juhas set sender to juhas@pa.msu.edu using -f Date: Mon, 5 Jan 2004 20:39:39 -0500 From: Pavol Juhas To: zsh users Subject: Re: problem piping output of shell builtin Message-ID: <20040106013939.GA11204@pa.msu.edu> Mail-Followup-To: zsh users References: <20040105203638.GA9567@pa.msu.edu> <20040105213010.GA83099@quark.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040105213010.GA83099@quark.localdomain> User-Agent: Mutt/1.4.1i On Mon, Jan 05, 2004 at 03:30:10PM -0600, Vincent Stemen wrote: > On Mon, Jan 05, 2004 at 03:36:38PM -0500, Pavol Juhas wrote: > > On Mon, Jan 05, 2004 at 07:26:15PM +0000, gj@sdf.lonestar.org wrote: ... > > > Why can't I pipe the output of 'jobs' thusly? > > > > AFAIK, all the shells run one side of the pipe in a subshell. bash > > executes subshell for the right side of the pipe, however zsh does > > so for the left side. Therefore the `jobs' command in > > `jobs|read line' is evaluated in the subshell of zsh, which has no > > knowledge about processes in the parent shell - and produces no > > output. Left side subshell is however advantageous in other > > situations, just compare > > > > zsh -c 'echo 10|read a; echo .$a' > > .10 > > bash -c 'echo 10|read a; echo .$a' > > . ... > > Under bash, at least, the semi-colon is ending the pipe command and > then executing "echo .$a" as new command in the original shell. So > you need to group the entire right side in the above example. > ie. > > $ echo 10 | (read a; echo .$a) > .10 > $ Exactly, bash has no way to read the output of the pipe to a variable (well, without creating temporary file). > > That is interesting. I did not know zsh did that by default. > However, I am not sure you are correct about zsh forking a sub-shell > for the left side of the pipe. If so, then local shell variables from > the parent shell should not be accessible unless they are exported, > but they are. > > $ x=foo > $ echo $x | read a; echo .$a > .foo > $ Variables are exported to the subshell, but if you change them in the left-side of the pipe, they will keep the original value in the parent shell, e.g. $ a=foo; { a=bar } | : $ echo $a foo $ a=foo; { a=bar } $ echo $a bar $ a=foo; : | { a=bar } $ echo $a bar $ i=foo; for i in 1 2; do echo $i; done | cat; echo $i 1 2 foo I think the most recent versions of zsh were expanded so they actually can handle `jobs|read line'. Pavol