Confusing string concatenation from stray quotes
A pattern like `"a"$b"c"` looks like broken syntax and often does not mean what it appears to. SC2140 flags this quoting layout.
Problem
Adjacent quoted and unquoted fragments such as `"-l""$dir""/file"` or `"a"$b"c"` concatenate into one word — that part is valid — but the alternating quote/no-quote pattern is a strong signal of a mistake: often a missing space, a stray extra quote, or a misunderstanding that quotes are needed around each embedded piece rather than around the whole expression. Even when the result happens to be correct, this style is hard to read and easy to get wrong the next time it is edited, since it is unclear at a glance where one "argument" ends and another begins.
Bad
path="-l""$dir""/config.conf"
echo $pathGood
path="-l$dir/config.conf"
echo "$path"Explanation
Bash concatenates adjacent strings/expansions into a single word whether or not each piece is separately quoted, so wrapping the whole expression in one pair of quotes is both sufficient and far more readable. Reserve separate quoted segments for cases where you are genuinely building up multiple distinct arguments.
Related
SC2086
SC2027
SC2089
When It Matters
Adjacent quoted and unquoted sections concatenate silently, so "a"b"c" is one word — and a stray quote in the middle of an argument produces a value that is almost right. The usual result is a path or URL with a missing or doubled character that only fails at the point of use. ShellCheck flags the pattern because it is far more often a typo than a deliberate concatenation.
Second Example
Note
Braces around the variable name — ${prefix} — remove any ambiguity about where the name ends, which is the readable way to build strings.
Exceptions
Mixing quote styles on purpose is legitimate when part of the string must stay literal, for example an awk program combined with a shell value. Keep those cases short and comment them, since the reader has to reason about three quoting contexts at once.
Faq
Q
Does the shell insert anything between adjacent quoted parts?
A
No. Concatenation is silent and produces a single word, which is exactly why a stray quote is hard to spot.
Q
When do I need ${} braces?
A
Whenever the character after the variable name could be part of a name — "${dir}name" — and generally for readability when building compound strings.
Q
Is single or double quoting better for URLs?
A
Double quotes when the URL contains variables, single quotes when it is entirely literal and may contain characters like ? and &.