mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 11:19:45 +08:00
Created SC1136 (markdown)
32
SC1136.md
Normal file
32
SC1136.md
Normal file
@@ -0,0 +1,32 @@
|
||||
## Unexpected characters after terminating `]`. Missing semicolon/linefeed?
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
if [ -e "foo.txt" ]: then
|
||||
echo "Exists"
|
||||
fi
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
if [ -e "foo.txt" ]; then
|
||||
echo "Exists"
|
||||
fi
|
||||
```
|
||||
### Rationale:
|
||||
|
||||
ShellCheck found unexpected characters after the `]` or `]]` in a `test` expression. In the example, a colon was accidentally used instead of a semicolon.
|
||||
|
||||
Similarly, a missing space before a comment (`[ -e foo ]#comment`), an additional square bracket (`[[ -e foo ]]]`), or a missing semicolon before a `then` on the same line (`if [ foo ]then`) can cause this warning.
|
||||
|
||||
Make sure the `]` or `]]` is not immediately followed by another shell word character.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
None
|
||||
|
||||
### Related resources:
|
||||
|
||||
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user