My site’s build script has a set command; but what does it do?
#!/usr/bin/env bash
set -euo pipefail
hugo --environment production --cleanDestinationDir
git add public
Here’s the breakdown of these flags:
-e: Exit immediately if a command exits with a non-zero status-u: Treat unset variables as an error when substituting-o pipefail: (“Option pipefail”) The return value of a pipeline is the status of the last command to exit with a non-zero status, or zero if no command exited with a non-zero status
These work together to make your script fail fast. As a sentence, they say:
“If this script won’t accept unset variables, and it will exit immediately if something fails, and if a chain fails, it will return the status of the thing that failed, not the last link in the chain.”
Seems like good scripting hygiene.