> > You can't do that. Bash has a builtin variable ("$?") for holding the exit
> > status, which you can then reassign to another variable if you need to
> > store it for later use. For example:
> >
> >     x=$?
> 
> ok, but what if i want to capture the exit status of grep in the following 
> command:
> grep "test" testfile.txt | tee test.out
> in that case $? always == 0, regardless of the exit status of grep.
That is because $? will always be the return value of the last command that
was run.  If you have a pipeline (a | b | c) it will be the value of the
return code of the last command in the pipeline, in your case 'tee'.  tee
finishes fine.

One trick I used to get around something like this where I needed a
pipeline and had to tell if the middle command succeded or not is:

a | ( b ; echo $? > /tmp/$$ ) | c

In your case this would look like:
tmpfile=/tmp/$$
(./configure ; echo $? > $tmpfile) | tee test.out
rval=`cat $tmpfile`; rm -rf $tmpfile


-- 
// Andrew MacKenzie  |  http://www.edespot.com
// Also, the Scots are said to have invented golf.  Then they had
// to invent Scotch whiskey to take away the pain and frustration.

Attachment: msg92646/pgp00000.pgp
Description: PGP signature

Reply via email to