|
|
|
|
|
by catern
3845 days ago
|
|
The only thing in this post that can be accurately called defensive is the use of "local" and "readonly". The rest is all just style preferences, which are rather subjective, and none of which are very appealing to me. Three real defensive bash programming tips are: - Quote all uses of variables - set -o nounset - set -o errexit And many others can be found in and around http://mywiki.wooledge.org/BashFAQ |
|
Using pipefail, if any program in a pipeline fails (i.e. exit code != 0), then the exit code for the pipeline will be != 0.
E.g. pipefail can be useful to ensure `curl does-not-exist-aaaaaaa.com | wc -c` doesn't exit with exit code 0..!