[Gllug] bash: return status of a command in a pipe?

ccooke ccooke-gllug at gkhs.net
Fri Sep 2 12:38:42 UTC 2005


On Fri, Sep 02, 2005 at 01:26:52PM +0100, Benedikt Heinen wrote:
> 
> Normally, I'd assume there just has to be a way for this, but - at the 
> moment, I'm a bit lost...
> 
> How do you get the return value of a command within a pipe?
> 
> i.e.  If I run:
> 
> 	make 2>&1 | tee make.out
> 
> As expected, $? always returns 0 - the result of 'tee'; independently of 
> whether make itself terminated successfully or encountered a problem.

>From bash(1):


       PIPESTATUS
              An  array  variable  (see Arrays below) containing a list of
	      exit status values from the processes in the 
	      most-recently-executed foreground pipeline (which may contain
	      only a single command).

So, you can access ${PIPESTATUS[0]} for your make result.

-- 
for((P=10**8,Q=P/100,X=320*Q/(`tput cols`-1),Y=210*Q/`tput lines`,y=-105*Q,v=\
-220*Q,x=v;y<105*Q;x=v,y+=Y));do for((;x<P;a=b=i=k=c=0,x+=X));do for((;a*a+b*\
b<2*P*P&&i++<99;a=((c=a)*a-b*b)/P+x,b=2*c*b/P+y));do :;done;(((j=(i<99?i%16:0\
)+30)>37?k=1,j-=8:0));echo -ne "\E[$k;$j"mE;done;echo -e \\E[0m;done # ccooke
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list