4 ms·
“I mean, who really switches on the option to make it die on unset variables?” I thought rachelbythebay has worked at Google, whose internal Bash style guide r
by yonran 14y ago
“I mean, who really switches on the option to make it die on unset variables?”
I thought rachelbythebay has worked at Google, whose internal Bash style guide recommends these settings:
set -o nounset # (aka set -u) abort on undefined variable reference
set -o errexit # (aka set -e) abort on any command failure
It may have also recommended enabling xtrace with line numbers, but I don’t remember.
- rachelbythebay 14y agoI did. I've also seen incredible abuses of said scripts. I'm talking about scripts that do things like unzipping (Python) PAR files, patching things they find inside, then running them to accomplish their own goals. The number of dependencies that introduced was just amazing. You really don't want to know how the sausage is made.
- nieve 14y agoEven if you can't force it on for everything, the bash construction ${variable:?message} lets you error out on individual null or unset values[1]. Unfortunately there doesn't seem to be as simple a way to handle all of null, unset, and empty string as rachelbythebay points out is needed. You can fudge it with a test against ${#parameter} (parameter length), but you don't get the direct error effect. [1] There are a lot of beautiful strangenesses in bash, especially the Parameter Expansion section of the manpage.