unset variable
A variable that has never been assigned, or has been removed with the unset builtin, which is different from one set to an empty string.
In more detail
Normally both expand to nothing, so a typo in a name goes unnoticed. set -u turns expanding an unset variable into an error, and ${var-default} tells the two cases apart.
Related terms
- set -u — The shell option that makes using an unset variable an error that stops the script, instead of silently expanding to nothing.
- default value expansion — The ${name:-fallback} form, which gives the fallback when the variable is unset or empty, without changing the variable.
- SC2154 — The ShellCheck warning for a variable that is used but never assigned in the file, often a typo or a value expected from the environment.
Taught in
- Shell Variables, The Environment And export — Bash Scripting & Command Line Automation
- Parameter Expansion: Defaults, Length, Slices — Bash Scripting & Command Line Automation
- Command Substitution And Subshells — Bash Scripting & Command Line Automation
- set -e, set -u And pipefail: Promises And Traps — Bash Scripting & Command Line Automation
- Debugging: set -x, bash -n And Reading The Error — Bash Scripting & Command Line Automation
- Style That Prevents Bugs — Bash Scripting & Command Line Automation