On Thu, 23 May 2002 at 11:01am (-0400), Joe Nestlerode wrote:
> Hello all.
>
> I have a script that could possibly generate the following error:
> "mount: /dev/fd0 is not a valid block device". I can't quite figure out
> how to get `trap' to catch that or similar errors. (I'd like to have it
> echo an error message to std out and abort the script.) Am I trying to
> use the wrong tool here?
Hmmm... well... the mount command itself already generates the error
message so you could just use it directly and simply abort on the error...
mount /dev/fd0 mumble 2>&1 || exit 1
... so mount's error message goes to stdout like you want and you exit if
mount did not suceed.
But if you really want to capture the output of mount and do something with
it.....
mntout=$(mount /dev/fd0 mumble 2>&1)
[ "$?" = "0" ] || {
echo "Error mounting /dev/fd0: $mntout"
exit 1
}
... as with most things involving the skin of felines which method you want
to use depends on exactly what your trying to acheive. The second is prolly
only really useful if you want to do something more with the error message
than just print it out.
M.
P.S. I'm not sure if this off topic for redhat-list or not... but moongroup
have a list specificaly for shell scripting questions which might be a
better place to ask...
http://moongroup.com/mailman/listinfo/shell.scripting
--
WebCentral Pty Ltd Australia's #1 Internet Web Hosting Company
Level 5, 100 Wickham St. Network Operations - Systems Engineer
PO Box 930, Fortitude Valley. phone: +61 7 3249 2557
Queensland, Australia 4006. pgp key id: 0x900E515F
_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list