From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15298 invoked from network); 5 Jan 2004 21:30:21 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 5 Jan 2004 21:30:21 -0000 Received: (qmail 21944 invoked by alias); 5 Jan 2004 21:30:04 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6982 Received: (qmail 21920 invoked from network); 5 Jan 2004 21:30:04 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 5 Jan 2004 21:30:04 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [68.1.17.114] by sunsite.dk (MessageWall 1.0.8) with SMTP; 5 Jan 2004 21:30:3 -0000 Received: from quark.localdomain ([68.12.75.33]) by lakemtao07.cox.net (InterMail vM.5.01.06.05 201-253-122-130-105-20030824) with ESMTP id <20040105213003.RNSU2432.lakemtao07.cox.net@quark.localdomain> for ; Mon, 5 Jan 2004 16:30:03 -0500 Received: from quark.localdomain (localhost.localdomain [127.0.0.1]) by quark.localdomain (8.12.9/8.12.9) with ESMTP id i05LUAuO083145 for ; Mon, 5 Jan 2004 15:30:10 -0600 (CST) (envelope-from vince@quark.localdomain) Received: (from vince@localhost) by quark.localdomain (8.12.9/8.12.9/Submit) id i05LUA9k083144 for zsh-users@sunsite.dk; Mon, 5 Jan 2004 15:30:10 -0600 (CST) Date: Mon, 5 Jan 2004 15:30:10 -0600 From: Vincent Stemen To: zsh-users@sunsite.dk Subject: Re: problem piping output of shell builtin Message-ID: <20040105213010.GA83099@quark.localdomain> References: <20040105203638.GA9567@pa.msu.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040105203638.GA9567@pa.msu.edu> User-Agent: Mutt/1.4.1i 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: > > Hi all, > > > > I'm migrating from bash to zsh. It hasn't been so bad because I'm sort of new > > to shell programming anyways ( though I did have "fun" figuring out that zsh > > arrays start incrementing from 1 as opposed to bash's 0 :). I thought I'd > > share the latest hiccup... > > > > 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' > . > > To access information in the zsh job table, you need to use the > builtin associate arrays jobtexts, jobstates and jobdirs, for example: > > for j in ${(k)jobstates}; do > print -- "[$j] ${jobstates[$j]} ${jobtexts[$j]} in ${jobdirs[$j]}" > done > > HTH, > > Pavol 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 $ 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 $ Vincent -- Vincent Stemen Avoid the VeriSign/Network Solutions domain registration trap! http://www.InetAddresses.net