Skip to content

array-in-string

Shellcorrectnessno fixdefault: offshell/shellcheck

Reports a double-quoted argument that holds $@ or ${array[@]} among other text, as in "files: $@".

Inside a string with other text, "$@" cannot give one word to each element. The first element is joined to the text before it and the last to the text after it, and the elements in between become separate words, so the string is split in a way that is easy to misread.

To fix, use $* (or ${array[*]}) to join them into one string, or put the array in a separate argument of its own.

Reported
...
flunk "failed: $@"
echo "a ${s[@]} b"
echo "$@" "${s[@]}"
...
IFS= read -r line
...
for l in "$@"; do :; done
eval "f ${args[@]}"
...
A=1 cmd "$B"
A=1 cmd "$A_"
...
shell:
lint:
rules:
array-in-string: warn # off (default), warn, error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line array-in-string 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 SC2145 partial Only the arguments of a command.