Skip to content

quote-array-element

Shellsuspiciousno fixdefault: offshell/shellcheck

Reports an unquoted $var or ${var} among the elements of an array assignment, as in arr=($x y).

The expansion is split into words and globbed, so one element becomes several, or none, and a * becomes file names. The shell does not know which variables hold a single word.

To fix, quote it: arr=("$x" y).

Reported
...
l+=($dl)
x=($dl "q" "$m")
...
echo "$@" "${s[@]}"
...
shell:
lint:
rules:
quote-array-element: warn # off (default), warn, error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line quote-array-element 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 SC2206 partial $var and ${var} among the elements, not other expansions.