ksh script, exit status and pipe

Ask a Question related to Linux / Unix Administration, Design and Development.

  1. #1

    Default ksh script, exit status and pipe

    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).
    Ian Wilson Guest

  2. Similar Questions and Discussions

    1. Net::telnet - need to retrieve the exit status
      Hi, I have a requirement in which that I have to retrieve both the command output and the exit status of the command through the Telnet->cmd()...
    2. pipe to a script hint
      Hi I can feed an email to a php script but am having problems figuring out how to grab the incoming data. At a guess a while loop reading...
    3. Script Exit Status
      Is there a way to have a perl script exit with a status code? For instance I have ascript that calls another script via system("somescript"); ...
    4. DBI: exit status, sql operation
      Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<bpqlpn$1rc0f7$1@ID-184292.news.uni-berlin.de>... From the url you pointed at: ...
    5. pipe a file to a perl script
      On Tue, 12 Aug 2003, Asif Iqbal wrote: Nevermind , I found the answer. -- Asif Iqbal...
  3. #2

    Default Re: ksh script, exit status and pipe

    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:

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

    --
    Stephane
    Stephane CHAZELAS Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139