mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC1141 (markdown)
36
SC1141.md
Normal file
36
SC1141.md
Normal file
@@ -0,0 +1,36 @@
|
||||
## Unexpected tokens after compound command. Bad redirection or missing ;/&&/||/|?
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
while echo "$2"; do true; done \
|
||||
head -n "$1"
|
||||
|
||||
while sleep 1; do date; done > my file
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
while echo "$2"; do true; done \
|
||||
| head -n "$1"
|
||||
|
||||
while sleep 1; do date; done > "my file"
|
||||
```
|
||||
### Rationale:
|
||||
|
||||
ShellCheck found unexpected trailing characters after a compound command.
|
||||
|
||||
The only things allowed after compound commands are redirections, shell keywords, and the various command separators (`;`, `&`, `|`, `&&`, `||`).
|
||||
|
||||
In the first example, a `|` was missing, causing `head` to appear as an unexpected trailing word, instead of being piped to. In the second example, a lack of quoting caused `file` to appear as an unexpected trailing word, instead of being part of the redirection.
|
||||
|
||||
Examine your statement and correct the problem.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
None
|
||||
|
||||
### Related resources:
|
||||
|
||||
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user