shellcheck
shellcheck copied to clipboard
SC3037: echo flags
For bugs
- Rule Id (if any, e.g. SC1000): SC3037
- My shellcheck version (
shellcheck --version
or "online"): 0.7.2 - [x] The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
- [x] I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit
Here's a snippet or screenshot that shows the problem:
#!/bin/sh
/bin/echo -e text
Here's what shellcheck currently says:
/bin/echo -e text
^-- SC3037: In POSIX sh, echo flags are undefined.
Here's what I wanted or expected to see:
/bin/echo
, /usr/bin/echo
, ... are binaries and are not builtin shell commands and are separate from the shell.
shellcheck shouldn't warn about undefined flags for these binaries.
In bash and dash echo is a builtin.
brother ~$ command -v echo
echo
brother ~$ command -v whoami
/usr/bin/whoami
You're right, this is confusing. ShellCheck currently only supports targeting shells, and has no notion of the particular userland. When you specify #!/bin/sh
, ShellCheck assumes (perhaps too zealously) that you additionally target a POSIX userland. It doesn't help that the warning says "In POSIX sh", which is just the universal prefix for messages of this type.
Supporting different userlands distinct from the shell is not currently high on the priority list, so please either ignore this warning, or use printf
which works on all shells and userlands.
Can't this be reopened? Even though this isn't a priority, it's not fixed. People will look at the suggestion and ignore this rule, introducing potential breakage whether it's a built-in or an actual binary.