shellcheck
shellcheck copied to clipboard
SC2140 false-positive with backslash for long strings
For bugs
- Rule Id (if any, e.g. SC1000): SC2140
- My shellcheck version (
shellcheck --version
or "online"): 0.8.0 - [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/bash
msg="this is a very long string which does not fit on a single line"\
"long string continues here"
echo "$msg"
Here's what shellcheck currently says:
In screpro.sh line 2:
msg="this is a very long string which does not fit on a single line"\
^-- SC2140 (warning): Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"?
For more information:
https://www.shellcheck.net/wiki/SC2140 -- Word is of the form "A"B"C" (B in...
Here's what I wanted or expected to see:
No error - though a space before \
or the following "
makes it go away, it seems confusing here.
I think the error is pointing out that the quotes ("
) sorrounding the (escaped) newline are superfluous:
#!/bin/bash
msg="this is a very long string which does not fit on a single line\
long string continues here"
echo "$msg"
should do the same an not trigger the rule.
edit:
To clarify the message:
-
A
→this is a very long string which does not fit on a single line
-
B
→\[newline]
-
C
→long string continues here
and thus -
msg
→"A"B"C"
(rather than"ABC"
)