Skip to content

echo-in-substitution

Shellsuspiciousno fixdefault: offshell/shellcheck

Reports a command substitution that only runs echo on words, as in $(echo $a $b).

It runs a subshell to print what the shell already has. Unquoted, it also splits and globs the words and, with some shells, interprets backslashes.

To fix, use the words directly, and quote them.

Reported
...
unset "words[0]"
...
[[ $a == "$b" ]]
x=$(echo $y)
x=$(echo "a" | tr a b)
...
shell:
lint:
rules:
echo-in-substitution: warn # off (default), warn, error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line echo-in-substitution 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 SC2116 partial Only $(echo words) with plain words.