Csh

From miki
Revision as of 00:31, 14 March 2013 by Mip (talk | contribs) (Created page with '== Tips / How-To == === Get status of a pipe === In CSH (and Bash), <code>$status</code> returns the status of the last process in a pipe (actually this is only true for Bash; fo…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Tips / How-To

Get status of a pipe

In CSH (and Bash), $status returns the status of the last process in a pipe (actually this is only true for Bash; for csh, it returns the status of the process that exited last!)

foo | bar
echo $status           # Print status of bar, not foo!

To still get the status of process foo, one has to use extra named pipe to carry on the information (see [1])

exec 3>&1 
status=`((ls /FOO ; echo $? > &4) | sed 1,1d 1>&3) 4>&1` 
exit $status