ksh script, exit status and pipe

  • Follow


I want to execute a command, redirect stderr and tee stdout
e.g.
   tar ... 2>foo.err | tee foo.log

however I also want to capture the exit status of the first command

   tar ... 2>foo.err | tee foo.log
   exitstatus = $?
simply gets the exit status of tee of course

   tar ... || exitstatus=$? 2>foo.err | tee foo.log
always sets exitstatus to zero, looks like I need to establish some 
precedence but brackets don't seem to help.

Is there an idiom for this?

Maybe I should hide the tar in a function?

Apologies if the above is a FAQ, I've RTFM where M = "Learning the Korn 
Shell" and "Unix Power Tools", I'm none the wiser (though opening the 
latter is always good for a half hour off-topic diversion).
0
Reply Ian 8/25/2004 11:00:44 AM

2004-08-25, 11:00(+00), Ian Wilson:
> I want to execute a command, redirect stderr and tee stdout
> e.g.
>    tar ... 2>foo.err | tee foo.log
>
> however I also want to capture the exit status of the first command
[...]

See question 13 of the comp.unix.shell FAQ:

http://home.comcast.net/~j.p.h/cus-faq.html#M

-- 
Stephane
0
Reply Stephane 8/25/2004 12:49:53 PM


1 Replies
617 Views

(page loaded in 0.082 seconds)

Similiar Articles:













7/30/2012 2:54:19 PM


Reply: