Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

local variable assignment and pipelines?

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

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

a=1 | echo $a      -> prints "1" on zsh, prints nothing on ash,pdksh,bash

	Dan Nelson

Messages sorted by: Reverse Date, Date, Thread, Author