name=World echo 'Hello $name' # Outputs Hello $name
name=World echo "Hello $name" # Outputs Hello World
ShellCheck found an expansion like
`cmd` in single quotes.
Single quotes express all such expansions. If you want the expression to expand, use double quotes instead.
If switching to double quotes would require excessive escaping of other metacharacters, note that you can mix and match quotes in the same shell word:
dialog --msgbox "Filename $file may not contain any of: "'`&;"\#%$' 10 70
If you know that you want the expression literally without expansion, you can ignore this message:
# We want this to output $PATH without expansion # shellcheck disable=SC2016 echo 'PATH=$PATH:/usr/local/bin' >> ~/.bashrc
ShellCheck also does not warn about escaped expansions in double quotes:
echo "PATH=\$PATH:/usr/local/bin" >> ~/.bashrc
disable=SC2016 in your
ShellCheck tries to increase the signal-to-noise ratio of this warning by ignoring certain well known commands that frequently expect literal dollar signs, such as
perl. However, there's a long tail of less common commands and flags that also frequently expect
$s, and it's not in ShellCheck's scope to try to keep track of them all. When you come across such a command, please ignore the suggestion, either permanently or for that one instance.
ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.