[clug] Tee eats the return code of the previous entry in the
pipeline
Damien Elmes
clug at repose.cx
Tue Mar 9 06:22:42 GMT 2004
Michael Still <mikal at stillhq.com> writes:
> Consider this:
>
> > cat fail
> #~/bin/bash
> exit 1
> > ./fail; echo $?
> 1
> > ./fail | tee - /tmp/foo; echo $?
> 0
>
> This makes me very sad. I want to be able to run a command, dump it's
> output to a file and to the console (in real time), and still have
> access to it's return code.
How about?
mobile[0]% cat > foo
exit 1
mobile[0]% exit=$((sh foo; echo $?) | tee - /tmp/foo); echo $exit
1
If the command printed output you could of course just use the last
line of output (since the exit code will be printed after any output
from the app / script.
Cheers,
--
Damien Elmes
More information about the linux
mailing list