Skip to content

quote-variable

Shellsuspiciousno fixdefault: warnshell/shellcheck

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.

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".

Reported
...
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) ]]
...
shell:
lint:
rules:
quote-variable: warn # off, warn (default), error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line quote-variable in a comment of the file’s language.

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.