bug-bash
[Top][All Lists]
Advanced

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

Re: declare overrides errexit


From: Marc Herbert
Subject: Re: declare overrides errexit
Date: Fri, 24 Sep 2010 16:43:38 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100907 Fedora/3.1.3-1.fc13 Thunderbird/3.1.3

Le 24/09/2010 15:38, Greg Wooledge a écrit :
> If this is turning into a general discussion of errexit (set -e) then
> please also see
> 
> http://mywiki.wooledge.org/BashFAQ/105   and
> http://fvue.nl/wiki/Bash:_Error_handling

These pages are great and should be read. But from experience, I
totally disagree with GreyCat's conclusion:

  GreyCat's personal recommendation is simple: don't use set -e. Add
  your own error checking instead.

My life has become incredibly easier since I started to put at the top
of every single of my scripts either a line like this:
    if $DEBUG; then set -e; fi
.. or even just a plain "set -e".

The only effort this requires is the need to append this from time to
time:
   cat foo || true # missing foo: expected, ignore

It is an order of magnitude more convenient and of course much safer
to append "|| true" from time to time than to append "|| exit 1" after
almost every line. Tested.

(The only other effort is to refrain to file a bug when set -e
sometimes fails to catch a failed command :-)

Bourne shell is the only programming language I know that ignores
errors by default. "set -e" does not completely repair this design
flaw but it goes a long and appreciated way.





reply via email to

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