Back in 1996, Tom Christiansen's celebrated "Csh Programming Considered Harmful" post showed how it can be done even in humble /bin/sh (but not in csh, of course ;-) as follows:
Consider the pipeline:You want to know the status of C, well, that's easy: it's in $?, or $status in csh. But if you want it from A, you're out of luck -- if you're in the csh, that is. In the Bourne shell, you can get it, although doing so is a bit tricky. Here's something I had to do where I ran dd's stderr into a grep -v pipe to get rid of the records in/out noise, but had to return the dd's exit status, not the grep's:A | B | Cdevice=/dev/rmt8 dd_noise='^[0-9]+\+[0-9]+ records (in|out)$' exec 3>&1 status=`((dd if=$device ibs=64k 2>&1 1>&3 3>&- 4>&-; echo $? >&4) +| egrep -v "$dd_noise" 1>&2 3>&- 4>&-) 4>&1` exit $status;
Update: Please note that the above block quoted text is a direct quote from Tom Christiansen's post.
In reply to Re: Redirecting STDOUT and standard error to file
by eyepopslikeamosquito
in thread Redirecting STDOUT and standard error to file
by ramya2005
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |