For new checks and feature suggestions
Here's a snippet or screenshot that shows a potential problem:
#!/bin/sh
echo "Hello World"
Here's what shellcheck currently says:
(nothing)
Here's what I wanted to see:
echo "Hello World"
^--- SC-XXXX: prefer single quotes unless quoting an expansion
Suggestion: echo 'Hello world'
Application
Identify all double-quoted strings, then:
- exclude strings that contain a
' (because we don't want to recommend rewriting "say 'cheese'!" as `'say '\''cheese'\''!')
- exclude strings that contain an expansion (in practice, just look for an unescaped ` , or an unescaped
$ that is followed by a digit or a letter or an underscore or any of {, (, [ , @, #, $, *, ?).
- exclude strings that are not just one quoted segment (e.g.
"Foo Bar" would be reported but 'Foo'\ "Bar" would not.
- change
\" to just " in any suggested replacement
Rationale
If one consistently uses single quotes whenever double quotes are not required, then the presence of double quotes becomes an indication to the reader that they have to pay more attention as something "special" is happening. (This is similar to the rationale for preferring $var over ${var}. In both cases the avoidance of "consistency" is intentional and preferable, because it provides clearer signalling.)
For new checks and feature suggestions
Here's a snippet or screenshot that shows a potential problem:
Here's what shellcheck currently says:
(nothing)
Here's what I wanted to see:
Application
Identify all double-quoted strings, then:
'(because we don't want to recommend rewriting"say 'cheese'!"as `'say '\''cheese'\''!')$that is followed by a digit or a letter or an underscore or any of{,(,[,@,#,$,*,?)."Foo Bar"would be reported but'Foo'\ "Bar"would not.\"to just"in any suggested replacementRationale
If one consistently uses single quotes whenever double quotes are not required, then the presence of double quotes becomes an indication to the reader that they have to pay more attention as something "special" is happening. (This is similar to the rationale for preferring
$varover${var}. In both cases the avoidance of "consistency" is intentional and preferable, because it provides clearer signalling.)