From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Sweth Chandramouli <sweth@astaroth.nit.gwu.edu>,
zsh-users@math.gatech.edu
Subject: Re: exit value of intermediate program in pipe
Date: Sun, 3 May 1998 18:35:49 -0700 [thread overview]
Message-ID: <980503183549.ZM1342@candle.brasslantern.com> (raw)
In-Reply-To: <19980503181509.09250@astaroth.nit.gwu.edu>
On May 3, 6:15pm, Sweth Chandramouli wrote:
: Subject: Re: Re: exit value of intermediate program in pipe
:
: in ksh i would do
:
: {
: grep -v bar |&
: print -p `/bin/blah ; exitstatus=$?`
: read -p output
: echo $output
: return $exitstatus
: }
You can do exactly that same thing, except insted of
grep -v bar |&
You'd say
coproc grep -v bar
Both print -p and read -p are the same in zsh as in ksh.
Of course, you probably want
while read -p output
do print -r $output
done
as each read consumes only one line, not the entire stream.
: for zsh, would i just do
:
: {
: grep -v bar coproc |
: >&p `/bin/blah ; exitstatus=$?`
That line doesn't do what you think. What you'd want is just
/bin/blah >&p
exitstatus=$?
: <&p output ; echo $output
That's not right either. You'd probably need
cat <&p
and you'd probably have to start it before you started /bin/blah, if
blah could potentially produce more than a few kbytes of output.
: return $exitstatus
: }
The last problem is that grep won't exit until it sees EOF on its stdin,
but >&p dups the coproc input without actually closing it. So the grep
won't get EOF when blah exits. You have to shut it down some other way;
the only thing I've found is to start another coprocess. I don't know
if this is a bug, or what.
So you get
{
coproc grep -v bar
cat <&p &
/bin/blah >&p
exitstatus=$?
coproc exit # Shuts down grep by closing its input, as
# a side-effect of starting a new coproc
# which then immediately exits. Ewww.
wait # Allows cat to finish, just in case.
return $exitstatus
}
I think { /bin/blah >>(grep -v bar) } is a lot nicer, don't you?
: what zsh really needs is something like the hawksbill book from
: oreilly for ksh, that gives a lot of examples and compares it to other
: shells
There's a lot of that in the FAQ, found in Etc/FAQ in the zsh dist.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
next prev parent reply other threads:[~1998-05-04 1:43 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-05-02 22:24 Steve Talley
1998-05-03 0:50 ` Sweth Chandramouli
1998-05-03 1:38 ` Timothy J Luoma
1998-05-03 2:08 ` Bart Schaefer
1998-05-03 6:17 ` Sweth Chandramouli
1998-05-03 9:30 ` Bart Schaefer
1998-05-03 22:15 ` Sweth Chandramouli
1998-05-04 1:35 ` Bart Schaefer [this message]
1998-05-04 4:54 ` Sweth Chandramouli
1998-05-04 9:43 ` Bernd Eggink
1998-05-04 11:42 ` Bart Schaefer
1998-05-04 12:03 ` Bernd Eggink
1998-05-04 15:59 ` Bart Schaefer
1998-05-05 11:39 ` Bernd Eggink
1998-05-05 17:03 ` zsh vs. ksh coproc redirection semantics Bart Schaefer
1998-05-06 10:47 ` Bernd Eggink
1998-05-06 16:00 ` Bart Schaefer
1998-05-07 7:17 ` Zoltan Hidvegi
1998-05-07 8:34 ` Andrew Main
1998-05-07 9:26 ` Bart Schaefer
1998-05-07 9:34 ` Andrew Main
1998-05-07 17:02 ` Zoltan Hidvegi
1998-05-07 9:18 ` Bart Schaefer
1998-05-07 17:10 ` Zoltan Hidvegi
1998-05-05 11:54 exit value of intermediate program in pipe Bernd Eggink
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=980503183549.ZM1342@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=sweth@astaroth.nit.gwu.edu \
--cc=zsh-users@math.gatech.edu \
/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).