A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/koalaman/shellcheck/wiki/SC2154 below:

SC2154 · koalaman/shellcheck Wiki · GitHub

var is referenced but not assigned.
var=name
n=42
echo "$var_$n.jpg"   # overextended

or

target="world"
echo "hello $tagret"  # misspelled

or

echo "Result: ${mycmd -a myfile}"  # trying to execute commands
var=name
n=42
echo "${var}_${n}.jpg"

or

target="world"
echo "hello $target"

or

echo "Result: $(mycmd -a myfile)"

ShellCheck has noticed that you reference a variable that is not assigned. Double check that the variable is indeed assigned, and that the name is not misspelled.

Note: This message 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.

ShellCheck intentionally does not attempt to figure out runtime or dynamic assignments like with source "$(date +%F).sh" or eval var=value. See SC2034 for an extended discussion of why this is the case.

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 the message with a directive.

POSIX - Parameter expansion:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4