shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

Improve SC2016 when argument is concated with single and double quotes

Open ap-wtioit opened this issue 2 years ago • 0 comments

For new checks and feature suggestions

  • [x] https://www.shellcheck.net/ (i.e. the latest commit) currently gives no useful warnings about this
  • [x] I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related

Here's a snippet or screenshot that shows the problem:


#!/bin/bash
bar="bar"
echo '$foo'"$bar"

Here's what shellcheck currently says:

[Line 3:](javascript:setPosition(3, 6))
echo '$foo'"$bar"
     ^-- [SC2016](https://www.shellcheck.net/wiki/SC2016) (info): Expressions don't expand in single quotes, use double quotes for that.

Here's what I wanted or expected to see:

When i'm using single and double quotes to concat an arg for a command, it's likely i'm aware of the difference between single and double quotes so SC2016 in this case is just anoying and not helping.

A more real life example where i'm actually using something like this:

sed 's,\(set \$variable \).*,\1"'"$new_variable_value"'";' "$file"

ap-wtioit avatar Jul 19 '22 13:07 ap-wtioit