shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

SC2064 is questionable

Open mcandre opened this issue 5 years ago • 7 comments

There are many reasons to use double quoted, immediate evaluation strings for traps. Basically, to parameterize them.

mcandre avatar May 09 '20 21:05 mcandre

Isn't it covered by the Exceptions?

If you don't care that the trap code is expanded early because the commands/variables won't change during execution of the script, or because you want to use the current and not the future values, then you can ignore this message.

mnuccioarpae avatar May 11 '20 06:05 mnuccioarpae

hen you can ignore this message.

That's what I'm griping about! I think the exceptions outnumber the utility of this rule.

mcandre avatar May 12 '20 02:05 mcandre

Well for bash at least, I think the heuristic should be, if the variable(s) are readonly (constant) then it shouldn't trigger.

kins-dev avatar Jan 20 '21 15:01 kins-dev

That's great for bash. But I strive to write pure POSIX sh for portability.

mcandre avatar Mar 25 '22 00:03 mcandre

POSIX supports read only: https://pubs.opengroup.org/onlinepubs/009695299/utilities/readonly.html

So that should be reasonable as well. It just is mutable results that might not do what users expect.

kins-dev avatar Mar 25 '22 01:03 kins-dev

Just seconding that this rule is inverted to my expectations as well.

Lazy evaluation feels like the more surprising mistake. Double quotes evaluating now is not surprising in shell.

3.3k disables https://github.com/search?q=SC2064&type=code

glennpratt avatar Oct 09 '23 23:10 glennpratt