Skip to content

useless-echo

Shellstyleno fixdefault: offshell/shellcheck

Reports an echo whose only argument is a command substitution, as in echo $(cmd).

The command already writes its output, so the echo adds a process and, unquoted, joins the lines with spaces and splits and globs the output.

To fix, run the command itself.

Reported
...
cat -n in.txt | grep x
cat a b | grep x
grep x in.txt
echo $(date)
echo "$(date)"
echo `date`
echo "$(date) now" $x
echo "$(date)s"
...
shell:
lint:
rules:
useless-echo: warn # off (default), warn, error

Enabled by the presets: shell/shellcheck.

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

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
shellcheck SC2005 full