default value expansion
The ${name:-fallback} form, which gives the fallback when the variable is unset or empty, without changing the variable.
In more detail
It is the usual way to give a script a sensible default, as in ${1:-report.txt}. The := form also assigns the fallback to the variable, and :? stops the script with an error message instead.
Example
out="${1:-report.txt}"Related terms
- parameter expansion — Replacing a dollar sign and a variable name with the variable's value, optionally transformed by an operator inside curly braces.
- set -u — The shell option that makes using an unset variable an error that stops the script, instead of silently expanding to nothing.
- positional parameters — The numbered variables $1, $2 and so on that hold the arguments given to a script or function, with $# holding how many there are.
Taught in
- The Field Separator, And Reading Lines Safely — Bash Scripting & Command Line Automation
- Parameter Expansion: Defaults, Length, Slices — Bash Scripting & Command Line Automation