Updated SC1001 (markdown)

koalaman
2017-07-05 09:59:09 -07:00
parent 5581d2324f
commit 58e4155f97

@@ -1,27 +1,37 @@
## This `\c` will be a regular 'c' in this context.
## This `\o` will be a regular 'o' in this context.
### Problematic code:
```sh
# Want literal backslash
echo Yay \o/
\git status # Non-POSIX way to suppress aliases
# Want linefeed
greeting=Hello\nWorld
# Want other characters
carriagereturn=\r
```
### Correct code:
```sh
echo 'Yay \o/'
command git status
greeting='Hello
World'
carriagereturn=$(printf '\r')
```
### Rationale:
Escaping something that doesn't need escaping sometimes indicates a bug.
You have escaped something that has no special meaning when escaped. The backslash will be simply be ignored.
If the backslash was supposed to be literal, single quote it.
If the backslash was supposed to be literal, single quote or escape it.
If the purpose is to run an external command rather than an alias, prefer `command`.
If you wanted it to expand to something, rewrite the expression. For linefeeds (`\n`), put them literally in quotes. For other characters, use POSIX `printf` or bash/ksh `$'...'`.
### Exceptions
If you have an alias and a function (as opposed to an external command), you can either ignore this message or use `"name"` instead of `\name` to quiet ShellCheck.
None. ShellCheck (as of 2017-07-03, commit 31bb02d6) will not warn when the first letter of a command is unnecessarily escaped, as this is frequently used to suppress aliases interactively.