mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC1143 (markdown)
52
SC1143.md
Normal file
52
SC1143.md
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
## This backslash is part of a comment and does not continue the line.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sed \
|
||||||
|
-e "s/HOST/$HOSTNAME/g" \
|
||||||
|
# -e "s/USER/$USER/g" \
|
||||||
|
-e "s/ARCH/$(uname -m)/g" \
|
||||||
|
"$buildfile"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sed \
|
||||||
|
-e "s/HOST/$HOSTNAME/g" \
|
||||||
|
-e "s/ARCH/$(uname -m)/g" \
|
||||||
|
"$buildfile"
|
||||||
|
|
||||||
|
# This comment is moved out:
|
||||||
|
# -e "s/USER/$USER/g" \
|
||||||
|
```
|
||||||
|
|
||||||
|
or using backticked, inlined comments:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sed \
|
||||||
|
-e "s/HOST/$HOSTNAME/g" \
|
||||||
|
`# -e "s/USER/$USER/g"` \
|
||||||
|
-e "s/ARCH/$(uname -m)/g" \
|
||||||
|
"$buildfile"
|
||||||
|
```
|
||||||
|
|
||||||
|
(ShellCheck recognizes this idiom and does not suggest quotes or `$()`, neither of which would have worked)
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
ShellCheck found a line continuation followed by a commented line that appears to try to do the same.
|
||||||
|
|
||||||
|
Backslash line continuations are not respected in comments, and the line instead simply terminates. This is a problem when commenting out one line in a multi-line command like the example.
|
||||||
|
|
||||||
|
Instead, either move the line away from its statement, or use an `` `# inline comment` `` in an unquoted backtick command substitution.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
### Related resources:
|
||||||
|
|
||||||
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user