zsh-workers
 help / color / mirror / code / Atom feed
From: Dan Nelson <dnelson@allantgroup.com>
To: zsh-workers@sunsite.dk
Subject: local variable assignment and pipelines?
Date: Fri, 18 Jul 2003 16:58:01 -0500	[thread overview]
Message-ID: <20030718215801.GB37697@dan.emsphone.com> (raw)


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


             reply	other threads:[~2003-07-18 22:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-18 21:58 Dan Nelson [this message]
2003-07-18 23:20 ` Philippe Troin
2003-07-21  9:59 ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030718215801.GB37697@dan.emsphone.com \
    --to=dnelson@allantgroup.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).