shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

SC2284 : echo ===

Open mickaeldotlambertatkontrondotcom opened this issue 2 months ago • 3 comments

Hello,

I hope you're doing all fine ; - )

Thanks for the greate job ! - )

I am trying to ramp up on shellcheck because I know I am not the coder of the year nor I have good habits at maintaining few thousands lines of bash scrips.

To start with I simply use some echo in my scripts to display things. I have "quickly" searched for echo through the wiki page without finding what I need. To be able to search my logs I use echo === $FUNCNAME: something kind of everywhere so I can search for === in logs.

Would SC2284 be adapted in case of more than two == in a row ? Or something else ?

  • [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
 [Line 3:](javascript:setPosition(3, 1))
echo === Hello
^-- [SC2284](https://www.shellcheck.net/wiki/SC2284) (error): Use [ x = y ] to compare values (or quote '==' if literal).
$

A good starting point is to ALWAYS use quotes with strings. That would silence all the warnings about unquoted variables as well. change your echo to have "=== whatever" and you are done, just as the text suggests.

brother avatar Oct 29 '25 10:10 brother

Hello Brother, Thanks for your answer ! Could you point me few "kind of" "community?" "references?" "or" "documentatons?" "or" "risks" (not sure of the wording) about the rational behind your recommendations ? Even in the shellcheck wiki ! - ) Then this cloud be closed. Thanks in advance, Have a nice day ; - ) Mickaël.

The two warnings that I have close and dear to my heart are https://www.shellcheck.net/wiki/SC2086 and https://www.shellcheck.net/wiki/SC2248.

Not sure there are any strong consensus around heavy quoting. I just tend to do it as a habit and because I have my programming background in other languages or something.

Greg's guide is probably the closest to a community style guide out there. And it has a page on quoting: https://mywiki.wooledge.org/Quotes#When_Should_You_Quote.3F My favorite part:

When in doubt, quote it.

brother avatar Oct 29 '25 15:10 brother