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

Re: exit value of intermediate program in pipe



} 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