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.
In more detail
If the variable really comes from outside, such as an exported setting, document it or give it a default with ${name:-}. Otherwise it is usually a misspelled name, and set -u would stop the script there.
Related terms
- ShellCheck — A linter for shell scripts that reports quoting mistakes, portability problems and common bugs, each with a numbered code.
- 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.
- environment variable — A named setting such as PORT=8000 that a program reads from its surroundings when it starts.
Taught in
- Shell Variables, The Environment And export — 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
- eval, And What To Use Instead — Bash Scripting & Command Line Automation