[aklug] Re: bash die

From: Mike Bishop <mbishop@mtaonline.net>
Date: Wed Sep 15 2010 - 15:44:43 AKDT

On Wed, Sep 15, 2010 at 01:16:50PM -0800, Christopher Howard wrote:
> Say you have a bash script where if any command fails, the scripts
> should stop. What would be the sensible way to deal with that?
>
> I was thinking, write some kind of die function, and then for each command:
>
> command_1 || die("command_1 failed")
> mount /this/file || die("failed to mount important filesystem")
> ...
>
> Or is there some better way to do this?
>

Used for years --

die()
{
        echo "$0: $1"
        exit ${2-9}
}

mount /this/file || die "failed to mount important filesystem"

Rgds,

--
Mike Bishop 
Willow, Alaska
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Wed Sep 15 15:44:52 2010

This archive was generated by hypermail 2.1.8 : Wed Sep 15 2010 - 15:44:52 AKDT