Variables must be defined before useSH-2154
A variable has been referenced that is not known to have been assigned earlier in the script. Double-check that the variable has indeed been assigned before being referenced and that it does not contain any typos.
Note: This issue only triggers for variables with lowercase characters in their name (foo
and kFOO
but not FOO
) due to the standard convention of using lowercase variable names for unexported, local variables.
Exceptions
The checker intentionally does not attempt to figure out runtime or dynamic assignments like with source "$(date +%F).sh"
or eval var=value
.
If you know for a fact that the variable is set, you can use ${var:?}
to fail if the variable is unset (or empty), initialize it to a default value if uninitialized with : "${var:=}"
, or explicitly initialize/declare it with var=""
or declare var
. You can also disable this issue by using a // skipcq: SH-2154
pragma.
References
POSIX - Parameter expansion: