Strict Mode
noun
say it: “STRIKT MOHD” /ˈstrɪkt ˈmoʊd/
A line at the top of a bash script that makes it stop at the first failing command, unset variable or failed pipe.
What is strict mode in a bash script?
Strict mode is the line set -euo pipefail near the top of a script. -e stops at the first command that fails, -u makes a misspelled or never-set variable an error, and -o pipefail fails a pipeline when any part fails. Keep it in scripts, not at the prompt.
#!/usr/bin/env bash
set -euo pipefail
photo_dir=photos
ls "$photo_dri/" # ./where.sh: line 4: photo_dri: unbound variable
In a sentence
- “With strict mode on, the misspelled photo_dri stopped the script instead of listing the whole computer.”
- “Sam starts every script with strict mode, the line set -euo pipefail.”
Level: Freelancer · More Unix terms at this level
Updated