# cat test
a="fred
echo$a
# ./test 2>&1 | tee file
./test: syntax error at line 1 : `"' unmatched
# echo $?
0
# cat file
./test: syntax error at line 1 : `"' unmatched
#
Now obviously we have the error to screen and file but the return
value after echo $? is returning that our commands at the prompt were
successful but we need it to return that the script 'test' failed.
Thanks for your advance wisdom
The $? that is 0 (indicating success) is NOT the exit status of the
./test command which failed; it is the exit status of the tee command,
which succeeded.
--
JP
JPR, sorry if I wasn't 100% clear, but that is my EXACT point. I want
to capture the return value of the ./test command regardless of
failure or not, but all we can get is the return value of tee. We
need to capture the stderr and sdtout and return value of ./test, and
once with have worked out all the syntax we can incorporate the
commands in a script which relies on the return value. Thanks
Some solutions:
$ result=`exec 3>&1; { ./test 2>&1; echo $? >&3; } | tee file`
$ echo $result
1
In ksh:
$ ./test 2>&1 |&
$ pid=$!
$ tee file <&p
$ wait $!
$ echo $?
1
In bash:
$ ./test 2>&1 | tee file
$ echo ${PIPESTATUS[0]}
1
John
--
John DuBois spc...@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
*blink* wow.. I do still have lots of learning to do with regards to
shells.. *grin* now where's that book!