Catching errors in a shell scripts

Simon Skogh simon at swedishdrunkard.com
Sun Apr 8 01:45:19 UTC 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Matthew Flaschen wrote:
>
> I see.  That's because standard output and standard error are different
> streams, and `command` (incidentially I find the equivalent $(command)
> easier to type) apparently doesn't capture standard error.  The below
> works, but there may well be a less hackish way.  This is a demo for
> capturing the error from trying to copy a non-existent file.  For all
> commands, it will capture both error and output to alloutput:
>
> tempoutput=`mktemp`
> cp nonexistent_file backup &> tempoutput;
> alloutput=`cat tempoutput`
> rm $tempoutput;
> echo "All output: $alloutput"
>
> mktemp generates a random filename, which helps prevent shenanigans.
>
> Matt Flaschen
>

The simplicity of this has me wanting to beat my head with a frying
pan. Although I considered at one point dumping output in files and
insert them into the DB by reading the file contents, it never
occurred to me to use it to bypass this issue. Although not the
ultimate solution (as you put it, there's probably that one less
"hackish" solution) this will do more than fine for my purpouse.

Thank you very much Matt, me and my sadistic frying pan both
appreciate it.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGGEkvz+/vk9aBZhMRAj60AKCcJMlF+SHhaMvSDFFyf1jHFOC7PwCgjyGN
MR91JtgZcdRteBIICxg/FPQ=
=Xtk/
-----END PGP SIGNATURE-----





More information about the ubuntu-users mailing list