On Fri, Dec 23, 2016 at 06:02:54PM +1100, [email protected] wrote:
> While it is documented to work that way doesn't mean it's a good idea to do 
> it.

the issue isn't about bash and '-e', it's about env breaking the ability to
pass options on the #! line. '-e' is just a trivial illustrative example.

with bash it's only a minor annoyance because most (or maybe all, i can't
remember) options can be enabled with a 'set' command inside the script
anyway.  For other languages, it can break the script entirely or, worse,
change the script's behaviour in subtle and "interesting" ways.


> cd $DIR
> rm -rf *

-e isn't a replacement for defensive programming around potentially dangerous
things, it's just a way to avoid uglifying your code by adding exit-status
checks after every trivial command. an uncaught non-zero exit code will abort
the script.

a saner, or more defensive, way to write that would be:

  cd "$DIR" && rm -rf *

or 

  cd "$DIR" \
    && rm -rf * \
    || exit 1

and it's worthwhile doing that (including quoting the $DIR variable) whether
you use 'bash -e', 'set -e' in the script, or neither.

craig

--
craig sanders <[email protected]>
_______________________________________________
luv-main mailing list
[email protected]
https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main

Reply via email to