Hacker News new | ask | show | jobs
by deskr 595 days ago
If you're writing scripts, use that and don't forget -e and -u

  -e      Exit  immediately if a pipeline (which may consist of a single simple command), a list, or a compound command (see SHELL GRAMMAR above), exits with a non-zero status

  -u      Treat  unset variables and parameters other than the special parameters "@" and "*" as an error when performing parameter expansion
1 comments

For `set -u` I mostly agree. For `set -e` see my comment below and Greg's wiki: http://mywiki.wooledge.org/BashFAQ/105
> and they still fail to catch even some remarkably simple cases

I totally agree. Although I'd say that there isn't anything "remarkably simple" about writing a bash script. Anything in the shell scripting world that seems remarkably simple is just because one hasn't realised the ghosts and horrors that lurk in the shadows.

But I'll use -e anytime. It feels like having a protective proton pack at least.