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