Hands-on task
Turn on strict mode
The script /root/deploy.sh keeps going even after a command fails and ends up reporting "success", although the copy failed. Make it fail-fast: the script must exit immediately with a non-zero code
- at the first command that fails;
- when it references a variable that has no value assigned (instead of a silent empty string);
- when any command inside a pipeline fails, not just the last one.
Turn this behavior on with shell options at the top of the script — don't rewrite the script's commands. In the end, running /root/deploy.sh must not create /root/status.txt.
- shellcheck
- set -euo pipefail
- strict mode
- exit codes
- fail-fast