ksh script, exit status and pipe

From: Ian Wilson (scobloke2_at_infotop.co.uk)
Date: 08/25/04

  • Next message: Stephane CHAZELAS: "Re: ksh script, exit status and pipe"
    Date: Wed, 25 Aug 2004 11:00:44 +0000 (UTC)
    
    

    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).


  • Next message: Stephane CHAZELAS: "Re: ksh script, exit status and pipe"

    Relevant Pages

    • Re: ksh script, exit status and pipe
      ... > I want to execute a command, redirect stderr and tee stdout ... > however I also want to capture the exit status of the first command ...
      (comp.unix.admin)
    • Re: How to move vi to /bin
      ... serves no purpose except foot-shooting. ... on pipes the exit status from the first command is the exit status of the ... There's plenty of reasons not to use csh and if you know what you're doing, ...
      (freebsd-questions)
    • Re: Exit status from command
      ... >> Any way I can get the exit status from my first command (or in general ... The requested page does not exist on this server. ... followed is either outdated or inaccurate. ...
      (comp.unix.shell)
    • Re: sed for sequential lines
      ... has happened"" and replace exit with #exit. ... I've been experimenting but can't quite make it work. ... /tmp $cat c ... The first command moves to the first line matching ...
      (comp.unix.programmer)
    • Re: sed for sequential lines
      ... has happened"" and replace exit with #exit. ... EDitor', because that's just an additional complication. ... The first command moves to the first line matching ... the pattern and then executes a +, ie moves to the next line. ...
      (comp.unix.programmer)