Catching errors in a shell scripts
Simon Skogh
simon at swedishdrunkard.com
Sun Apr 8 02:29:08 UTC 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Matthew Flaschen wrote:
> Simon Skogh wrote:
>> 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.
>
> My experience is, the simpler the problem, the less likely I can
> figure it out without help. This one actually took me a few
> minutes, though.
>
> Matt Flaschen
>
Can't agree more. Now I'm just trying to beat sed into submission
(we've never been on good terms) to make the output escape single
quotes, i.e. turn ' into \' so the queries won't break, and Google's
not playing nicely either right now, so it's time for a break I reckon.
Simon
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGGFN0z+/vk9aBZhMRAlnPAJ9pdxi/mOrnR/naTv0ADACswY+jtACfbDSG
6Q9l8gsnnCCMMhIG6g46WkU=
=Madd
-----END PGP SIGNATURE-----
More information about the ubuntu-users
mailing list