Updated SC2016 (markdown)

Eisuke Kawashima
2025-07-29 20:44:44 +09:00
parent 72caf28d33
commit d2292fdc1e

@@ -30,19 +30,19 @@ 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:
```
```sh
# We want this to output $PATH without expansion
# shellcheck disable=SC2016
echo 'PATH=$PATH:/usr/local/bin' >> ~/.bashrc
```
```
```sh
# We also want this variable to expand "$BASH_SOURCE:$LINE..." during an execution trace.
# shellcheck disable=SC2016
PS4='+$BASH_SOURCE:$LINENO:$FUNCNAME: '
```
```
```sh
# We want to control which environment variables envsubst replaces
# shellcheck disable=SC2016
envsubst '${SERVICE_HOST}:${SERVICE_PORT}' config.template > config
@@ -50,11 +50,10 @@ envsubst '${SERVICE_HOST}:${SERVICE_PORT}' config.template > config
ShellCheck also does not warn about escaped expansions in double quotes:
```
```sh
echo "PATH=\$PATH:/usr/local/bin" >> ~/.bashrc
```
This suggestion is primarily meant to help newbies who assume single and double quotes are basically the same, like in Python and JavaScript. It's not at all meant to discourage experienced users from using single quotes in general. If you are well aware of the difference, please do not hesitate to permanently disable this suggestion with `disable=SC2016` in your `.shellcheckrc`.
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 `sh` and `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.