On 11:01 23 May 2002, Joe Nestlerode <[EMAIL PROTECTED]> wrote:
| 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?

Yep. "trap" catches signals.
generally you never care much about error messages.
Instead you examine the exit status of the command (which is easy in the
shell because every command is an expression in a sense).

The exit status of a command is zero when it works and nonzero on failure.
So your script might read:

        mount /dev/fd0 /some/where || exit 1
            
BTW, you NEVER issue error messages to stdout. Send them to stderr,
That's what it's for.

So:

        mount /dev/fd0 /some/where || { echo "$0: can't mount!" >&2
                                        exit 2
                                      }

In this way, a failing mount prints your "echo" error to stderr and
exist the script with non-zero status (so that in turn, an outside user
can test your script just as you have tested mount).
-- 
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

Not at all tricky.  We do this sort of stuff every day before breakfast.
Then I fly to work on my winged pig, Swilma.
        - David Chase, [EMAIL PROTECTED]



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to