[clug] Tee eats the return code of the previous entry in the pipeline

Kim Holburn kim.holburn at anu.edu.au
Tue Mar 9 06:48:34 GMT 2004


At 5:22 PM +1100 2004/03/09, Damien Elmes wrote:
>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.

How about :

screen
(window 1) cat fail > /tmp/foo
(window 2 (^A^C)) less +F /tmp/foo

-- 
--
Kim Holburn 
Network Consultant - Telecommunications Engineering
Research School of Information Sciences and Engineering
Australian National University - Ph: +61 2 61258620 M: +61 0417820641
Email: kim.holburn at anu.edu.au  - PGP Public Key on request

Life is complex - It has real and imaginary parts.
     Andrea Leistra (rec.arts.sf.written.Robert-jordan)


More information about the linux mailing list