5 ms·
While not as common as nounset and errexit, pipefail is a useful option as well (set -o pipefail). Using pipefail, if any program in a pipeline fails (i.e. exi
by krallin 11y ago
While not as common as nounset and errexit, pipefail is a useful option as well (set -o pipefail).
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..!
- michaelhoffman 11y agoYou can set all three of them in a single line. Set up your Bash template with this today: set -o nounset -o pipefail -o errexit
- vog 11y agoI usually shorten this to: set -eu -o pipefail
- michaelhoffman 11y agoI used to do that but the long versions are more understandable by other people who will look at the script.