mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC1001 (markdown)
24
SC1001.md
24
SC1001.md
@@ -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.
|
Reference in New Issue
Block a user