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

Re: exit value of intermediate program in pipe



	Author:        talley@xxxxxxxxxxxxxxxxxxxxxxx (Steve Talley)
	Original-Date: Sat, 2 May 1998 16:24:40 -0600
	Message-ID:    <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.
>
> Is there any way to do this?

Do you ming a tempfile ?

foo () {
	tmp=/tmp/$0.$USER.$$

	/bin/blah > $tmp 2>&1
	exit="$?"
	
	grep -v foo $tmp && /bin/rm -f $tmp
	
	exit $exit

}

You don't have to use /tmp as the tempdir if you have security concerns..  
$HOME would work just as well.

TjL

ps -- if you use this function in your shell, doesn't it kill the shell ?




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