A Linux administrator wants to ensure a bash script stops execution immediately if any command fails. Which line should be added to the script?
Trap 1: set -x
This enables debug tracing, not exit on error.
Trap 2: set -u
This treats unset variables as an error, but does not exit on command failure.
Trap 3: set -o pipefail
This only affects pipelines; it does not cause exit on all errors.
- A
set -x
Why wrong: This enables debug tracing, not exit on error.
- B
set -u
Why wrong: This treats unset variables as an error, but does not exit on command failure.
- C
set -e
Correct. This causes the script to exit on any command failure.
- D
set -o pipefail
Why wrong: This only affects pipelines; it does not cause exit on all errors.