-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2016
Vidar Holen edited this page Aug 27, 2021
·
11 revisions
name=World
echo 'Hello $name' # Outputs Hello $name
name=World
echo "Hello $name" # Outputs Hello World
ShellCheck found an expansion like $var
, $(cmd)
, or `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
- StackOverflow: How do I use variables in single quoted strings?