Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: exit value of intermediate program in pipe
- X-seq: zsh-users 1499
 
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
 
- To: talley@xxxxxxxxxxxxxxxxxxxxxxx (Steve Talley), zsh-users@xxxxxxxxxxxxxxx
 
- Subject: Re: exit value of intermediate program in pipe
 
- Date: Sat, 2 May 1998 19:08:31 -0700
 
- In-reply-to: <199805022224.QAA03113@xxxxxxxxxxxxxxxxxxxxxx>
 
- References: <199805022224.QAA03113@xxxxxxxxxxxxxxxxxxxxxx>
 
} foo () {
} 	/bin/blah | grep -v "foo"
} }
} 
} I would like this function to exit with the exit value from the
} /bin/blah process, but it exits with the exit value from grep instead.
You can do this:
    foo() {
    	/bin/blah >>(grep -v "foo")
    }
That effectively runs grep in the background and blah in the foreground,
while still connecting them with a pipe.  Then you get the exit status of
blah, but with the side effect that the function returns as soon as blah
finishes, without waiting for the grep -- which may not be what you want.
I don't think there's any other way to do this without using a temp file.
    foo() {
	local outfile=${TMPPREFIX}blah.out
	/bin/blah > $outfile
	local exitval=$?
	grep -v "foo" $outfile
	command rm -f $outfile
	return $exitval
    }
-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com
Messages sorted by:
Reverse Date,
Date,
Thread,
Author