quote-variable
What it does
Section titled “What it does”Reports an unquoted $var or ${var} in the arguments of a command. The rule does not know which variables hold only a number or a single word.
Why it matters
Section titled “Why it matters”The value is split on blanks and globbed, so a value with a space becomes several arguments, an empty one disappears (and a test such as [ $x = a ] becomes a syntax error), and a * becomes file names.
To fix, quote it: "$var".
Example
Section titled “Example”...rm '$(literal)' "$(ok)"echo $((1 + 2))diff <(sort a) <(sort b); echo <(date)rm $file ${dir}/x "$file" '$file' $1 $?rm --opt=$value "x $y"...cp $* dir ${arr[*]}now=`date`...[ $x -eq 0 ][[ $x = $y ]] && [[ -n $(foo) ]]...Configuration
Section titled “Configuration”shell: lint: rules: quote-variable: warn # off, warn (default), errorEnabled by the presets: shell/shellcheck.
Suppress one line with sudsy-disable-next-line quote-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 | SC2086 |
partial | The arguments of a command and the words of [ ]; not the command name, assignments, loop lists, redirect targets, [[ ]] or the inside of $(...), and it does not know which variables hold a number or a literal. |