rules_directory is referenced but not assigned. Invalid
rules_safe0="${rules_directory}/safe.0.sed"
- Read upRead up
- Exclude checks
var is referenced but not assigned.
Problematic code:
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
Correct code:
var=name
n=42
echo "${var}_$n.jpg"
or
target="world"
echo "hello $target"
or
echo "Result: $(mycmd -a myfile)"
Rationale:
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.
Exceptions:
ShellCheck 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), or explicitly initialize/declare it with var=""
or declare var
. You can also disable the message with a [[directive]].
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Shells disambiguate $(( differently or not at all. For $(command substition), add space after $( . For $((arithmetics)), fix parsing errors. Open
GREP=$((ugrep --version >/dev/null 2>&1 && echo 'ugrep') \
- Read upRead up
- Exclude checks
Shells disambiguate $(( differently or not at all. If the first $( should start command substitution, add a space after it.
Problematic code:
echo "$((cmd "$@") 2>&1)"
Correct code:
echo "$( (cmd "$@") 2>&1)"
Rationale:
You appear to be using $((
with two (or more) parentheses in a row, where the first $(
should open a subshell.
This is an ill-defined structure that is parsed differently between different shells and shell versions. Prefer adding spaces to make it unambiguous, both to shells and humans.
Consider the $(((
in $(((1)) )
:
Ash, dash and Bash 1 parses it as $(( (
and subsequently fail to find the matching ))
. Zsh and Bash 2+ looks ahead and parses it as $( ((
. Ksh parses it as $( ( (
.
Exceptions:
Alternatively, you may indeed have correctly spaced your parentheses, but ShellCheck failed to parse $((
as an arithmetic expression while accidentally succeeding in parsing it as $(
+ (
.
In these cases, double check the syntax to ensure ShellCheck can parse the $((
, or ignore this error and hope that it won't affect analysis too severely.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Tips depend on target shell and yours is unknown. Add a shebang. Open
function warning {
- Read upRead up
- Exclude checks
Tips depend on target shell and yours is unknown. Add a shebang.
Problematic code:
echo "$RANDOM" # Does this work?
Correct code:
#!/bin/sh
echo "$RANDOM" # Unsupported in sh. Produces warning.
or
#!/bin/bash
echo "$RANDOM" # Supported in bash. No warnings.
Rationale:
Different shells support different features. To give effective advice, ShellCheck needs to know which shell your script is going to run on. You will get a different numbers of warnings about different things depending on your target shell.
ShellCheck normally determines your target shell from the shebang (having e.g. #!/bin/sh
as the first line). The shell can also be specified from the CLI with -s
, e.g. shellcheck -s sh file
.
If you don't specify shebang nor -s
, ShellCheck gives this message and proceeds with some default (bash
).
Note that this error can not be ignored with a [[directive]]. It is not a suggestion to improve your script, but a warning that ShellCheck lacks information it needs to be helpful.
Exceptions
None. Please either add a shebang or use -s
.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.