unassigned-variable
What it does
Section titled “What it does”Reports a lower case variable that the file reads and never assigns, reads with read, getopts, local or a for loop, or guards with a default (${name:-x}). Names with an upper case letter are left alone: they are the environment’s.
Why it matters
Section titled “Why it matters”A variable that is read and never set is usually a misspelling of another one, and it expands to nothing without an error, so rm -rf "$dir/"* with dir misspelled becomes rm -rf /*.
To fix, correct the name, or assign the variable.
Example
Section titled “Example”used=1...echo "$used" "$status" "${output:-}" "${missing[@]}"local_var() {... local -a list=(a b)...arr[0]=xecho "${arr[0]}" "${#arr[@]}" "$#" "$@" "$1" "$_"cat <<EOF$heredoc_read ${FROM_ENV}EOFecho '$single' "\$escaped"while getopts "ab:" opt; do...Configuration
Section titled “Configuration”shell: lint: rules: unassigned-variable: warn # off (default), warn, errorEnabled by the presets: shell/shellcheck.
Suppress one line with sudsy-disable-next-line unassigned-variable in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| shellcheck | SC2154 |
partial | Lower case names only, reported at the first read. |