<div dir="auto">Probably the pseudo-function (preprocessor symbol) name “try” would be better than “catcher.”</div><div dir="auto"><br></div><div dir="auto">Hmm</div><div dir="auto"><br></div><div dir="auto">Also you mentioned a function like:</div><div dir="auto"><br></div><div dir="auto">exit_on_failure($?, “reason”) # not sure of syntax</div><div dir="auto"><br></div><div dir="auto">Is nice and clean as well.</div><div dir="auto"><br></div><div dir="auto">Then it’s up to the script writer to write any messages to a log, or send stderr to the script caller.</div><div dir="auto"><br></div><div dir="auto">Possibly also writing out exit status might be helpful, if non-zero.</div><div dir="auto"><br></div><div dir="auto">What I’m running into is problems like bc and unzip being unavailable on some systems. I can install unzip on cygwin i think, but installing stuff like bc on Git for Windows seems troublesome, and I may bite the bullet and install msys2.</div><div dir="auto"><br></div><div dir="auto">John </div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jul 22, 2023 at 9:22 PM John Carlson <<a href="mailto:yottzumm@gmail.com">yottzumm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><div dir="auto">Thanks Leonard, i was hoping to use a function because i have a whole list of pipelines to run in my script.</div><div dir="auto"><br></div><div dir="auto">Something like:</div><div dir="auto"><br></div><div dir="auto">catcher “oops” (sed ‘s/ //‘ | tr “\n” “ “ | ….)</div><div dir="auto">catcher…</div><div dir="auto"><br></div><div dir="auto">I don’t want a script for catcher. If a function won’t suffice, a preprocessor will.</div><div dir="auto"><br></div><div dir="auto">You probably want 2>> instead of 2> but I’m willing to hear your reasoning.</div><div dir="auto"><br></div><div dir="auto">Thanks for your help!</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jul 22, 2023 at 9:01 PM Leonard Daly <<a href="mailto:Leonard.Daly@realism.com" target="_blank">Leonard.Daly@realism.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">
<div>
<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 style="font-family:monospace"><font face="monospace" style="font-family:monospace;color:rgb(0,0,0)">(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 href="https://unix.stackexchange.com/questions/164482/pipe-redirect-a-group-of-commands" target="_blank">https://unix.stackexchange.com/questions/164482/pipe-redirect-a-group-of-commands</a></p>
<p>Leonard Daly<br>
</p></div><div>
<p><br>
</p>
<p><br>
</p>
<div>On 7/21/2023 10:15 PM, John Carlson
wrote:<br>
</div>
</div><div><blockquote type="cite"></blockquote></div><div><blockquote type="cite">
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></fieldset>
</blockquote></div><div><blockquote type="cite"><pre style="font-family:monospace">_______________________________________________
x3d-public mailing list
<a href="mailto:x3d-public@web3d.org" style="font-family:monospace" target="_blank">x3d-public@web3d.org</a>
<a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org" style="font-family:monospace" target="_blank">http://web3d.org/mailman/listinfo/x3d-public_web3d.org</a>
</pre></blockquote></div><div><blockquote type="cite">
</blockquote>
<div>-- <br>
<b>Leonard Daly</b><br>
3D Systems Engineering<br>
President, Daly Realism - <i>Creating the Future</i><br>
</div>
</div>
_______________________________________________<br>
x3d-public mailing list<br>
<a href="mailto:x3d-public@web3d.org" target="_blank">x3d-public@web3d.org</a><br>
<a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org" rel="noreferrer" target="_blank">http://web3d.org/mailman/listinfo/x3d-public_web3d.org</a><br>
</blockquote></div></div>
</blockquote></div></div>