bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error handling question


From: Chet Ramey
Subject: Re: Error handling question
Date: Mon, 9 Nov 2009 08:59:51 -0500

>     Sorry, but I don't understand at all... So please bare with me and
> make me understand.
> 
>     So I've interpreted `set -e` as a way to tell bash to treat any
> process exiting with non-zero (and not succeeded by a || ), as an
> error and end the current shell / sub-shell.

Close.  There are a few conditions under which set -e has no effect.  The
&& and || operators are a two places, but there are more.

>     So my question is how can I solve this problem? (And obtain the
> needed behaviour.) (I see `()` and `{}` as blocks in normal
> programming languages (of course with some particularities), and
> non-zero exit codes as exceptions. And this is very helpful to write
> robust bash scripts.)

Don't rely on set -e if its behavior is not what you want.  Check exit
statuses yourself and stop execution when appropriate.  You could use
set -e and check exit statuses in the exception cases to reduce the
amount of extra work.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]