<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Not sure why you would want a script as this is almost always
      done in-line.</p>
    <p>$? contains the exit status. 0 is almost always success (I don't
      know where it is not) and != 0 is failure. Error message is
      written to STDERR unless you direct a command to fail silently.</p>
    <p>So something like<br>
    </p>
    <pre><font face="monospace">(A | B | C ...) 2> /tmp/pipe-$$.err
if [ $? -ne 0 ]
then
  exitCode=$?
  cat /tmp/pipe-$$.err
  exit $exitCode
fi</font></pre>
    <p>Passing the piped command to a function can be
      dangerous/difficult because of shell interpolation and quoting.
      Also note that the piped output (STDOUT) is printed on the default
      (at the time of the pipe) output (probably console), and
      pipe-$$.err is never cleaned up (deleted). That is not really bad
      because most systems delete files after 24-48 hours in /tmp. If
      there are no errors, then /tmp/pipe-$$.err is never created.<br>
    </p>
    <p>Additional useful info:
<a class="moz-txt-link-freetext" href="https://unix.stackexchange.com/questions/164482/pipe-redirect-a-group-of-commands">https://unix.stackexchange.com/questions/164482/pipe-redirect-a-group-of-commands</a></p>
    <p>Leonard Daly<br>
    </p>
    <p><br>
    </p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 7/21/2023 10:15 PM, John Carlson
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAGC3UEnbuuVhZgauorj=Ew1j+xJ74jHqh32eJnyU15RP9Wq7SQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      Linux folks:
      <div dir="auto"><br>
      </div>
      <div dir="auto">Does anyone have a bash function (not a separate
        script) to check the exit status of the passed in  pipeline or
        passed in exit status, print out the passed in error message,
        and exit the script if the exit status indicates failure?</div>
      <div dir="auto"><br>
      </div>
      <div dir="auto">Thanks!</div>
      <div dir="auto"><br>
      </div>
      <div dir="auto">Should be fairly easy to write?</div>
      <div dir="auto"><br>
      </div>
      <div dir="auto">John </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
x3d-public mailing list
<a class="moz-txt-link-abbreviated" href="mailto:x3d-public@web3d.org">x3d-public@web3d.org</a>
<a class="moz-txt-link-freetext" href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org">http://web3d.org/mailman/listinfo/x3d-public_web3d.org</a>
</pre>
    </blockquote>
    <div class="moz-signature">-- <br>
      <b>Leonard Daly</b><br>
      3D Systems Engineering<br>
      President, Daly Realism - <i>Creating the Future</i><br>
    </div>
  </body>
</html>