mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC1001 (markdown)
12
SC1001.md
12
SC1001.md
@@ -6,11 +6,8 @@
|
||||
# Want literal backslash
|
||||
echo Yay \o/
|
||||
|
||||
# Want linefeed
|
||||
greeting=Hello\nWorld
|
||||
|
||||
# Want other characters
|
||||
carriagereturn=\r
|
||||
bell=\a
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
@@ -18,10 +15,7 @@ carriagereturn=\r
|
||||
```sh
|
||||
echo 'Yay \o/'
|
||||
|
||||
greeting='Hello
|
||||
World'
|
||||
|
||||
carriagereturn=$(printf '\r')
|
||||
bell="$(printf '\a')"
|
||||
```
|
||||
|
||||
### Rationale:
|
||||
@@ -30,7 +24,7 @@ You have escaped something that has no special meaning when escaped. The backsla
|
||||
|
||||
If the backslash was supposed to be literal, single quote or escape it.
|
||||
|
||||
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 `$'...'`.
|
||||
If you wanted it to expand to something, rewrite the expression to use `printf` (or in bash, `$'\t'`). If the sequence in question is `\n`, `\t` or `\r`, you instead get a [[SC1012]] that describes this.
|
||||
|
||||
### Exceptions
|
||||
|
||||
|
Reference in New Issue
Block a user