array-in-string
What it does
Section titled “What it does”Reports a double-quoted argument that holds $@ or ${array[@]} among other text, as in "files: $@".
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”...flunk "failed: $@"echo "a ${s[@]} b"echo "$@" "${s[@]}"...IFS= read -r line...for l in "$@"; do :; doneeval "f ${args[@]}"...A=1 cmd "$B"A=1 cmd "$A_"...Configuration
Section titled “Configuration”shell: lint: rules: array-in-string: warn # off (default), warn, errorEnabled by the presets: shell/shellcheck.
Suppress one line with sudsy-disable-next-line array-in-string 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 | SC2145 |
partial | Only the arguments of a command. |