koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
35.92k stars 1.76k forks source link

SC2016 should not apply to single-quoted printf patterns #1293

Open blueyed opened 6 years ago

blueyed commented 6 years ago
In t-printf-I2016.sh line 5:
printf 'eval "$(pyenv init - %s)"' "$shell"
       ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

Here printf is used on purpose, and therefore SC2016 should not be emitted.

btw: when using double quotes and a variable in there you will get:

Don't use variables in the printf format string. Use printf "..%s.." "$foo". (I2059)

koalaman commented 6 years ago

Is there a way for ShellCheck to know that this is done on purpose? For example, this snippet has the same format but doesn't do it on purpose:

 colorize() { echo "$(tput setaf 3)$*$(tput sgr0)"; }
 printf 'Score: $(colorize %0.3f)\n' '1.2345'