From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15555 invoked from network); 18 Jul 2003 22:04:52 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 18 Jul 2003 22:04:52 -0000 Received: (qmail 25290 invoked by alias); 18 Jul 2003 22:04:45 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 18867 Received: (qmail 21556 invoked from network); 18 Jul 2003 21:58:04 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 18 Jul 2003 21:58:04 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [199.67.51.101] by sunsite.dk (MessageWall 1.0.8) with SMTP; 18 Jul 2003 21:58:3 -0000 Received: (from dan@localhost) by dan.emsphone.com (8.12.9/8.12.9) id h6ILw1i2065920 for zsh-workers@sunsite.dk; Fri, 18 Jul 2003 16:58:01 -0500 (CDT) (envelope-from dan) Date: Fri, 18 Jul 2003 16:58:01 -0500 From: Dan Nelson To: zsh-workers@sunsite.dk Subject: local variable assignment and pipelines? Message-ID: <20030718215801.GB37697@dan.emsphone.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-OS: FreeBSD 5.1-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.4i A coworker came to me with a scripting question, but after answering his question I looked at it again and wondered why his command even worked in the first place! Here's his command: rs=`fmt_layout -l bmg400.org.afmt -r` | fs=`ls -l /io1/auto/bmg/EMSSND03.org | awk '{ print $5 }'` | recs=`expr $fs / $rs` | rem=`expr $fs % $rs` | echo $rem (basically it gets the record length and filesize of a fixed-width text file, then computes the number of records and extra bytes) Obviously, all those pipes (except the ls | awk one) should be semicolons. The big question is why are all the local variables set in the pipeline visible to the final command? Is it because zsh realizes all the commands are variable assignments and runs them in serial in the parent process? That's what a ktrace seems to indicate is happening. It's sort of a neat feature, but is this supposed to happen? I know zsh guarantees that the last pipeline command is run in the main process and can modify its variables, but what about the intermediate ones? a=1 | echo $a -> prints "1" on zsh, prints nothing on ash,pdksh,bash -- Dan Nelson dnelson@allantgroup.com