zsh-workers
 help / color / mirror / code / Atom feed
* local variable assignment and pipelines?
@ 2003-07-18 21:58 Dan Nelson
  2003-07-18 23:20 ` Philippe Troin
  2003-07-21  9:59 ` Peter Stephenson
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Nelson @ 2003-07-18 21:58 UTC (permalink / raw)
  To: zsh-workers


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-07-21  9:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-18 21:58 local variable assignment and pipelines? Dan Nelson
2003-07-18 23:20 ` Philippe Troin
2003-07-21  9:59 ` Peter Stephenson

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).