mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC1033 (markdown)
43
SC1033.md
Normal file
43
SC1033.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
## Test expression was opened with double `[[` but closed with single `]`. Make sure they match.
|
||||||
|
|
||||||
|
(or SC1034 for vice versa)
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
[[ -z "$var" ]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
[[ -z "$var" ]]
|
||||||
|
```
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
ShellCheck found a test expression `[ ... ]` (POSIX) or `[[ ... ]]` (ksh/bash), but where the opening and closing brackets did not match (i.e. `[[ .. ]` or `[ .. ]]`). The brackets need to match up to work.
|
||||||
|
|
||||||
|
Note in particular that `[..]` do *not* work like parentheses in other languages. You can not do:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Invalid
|
||||||
|
[[ x ] || [ y ]]
|
||||||
|
```
|
||||||
|
Instead, use one of
|
||||||
|
You would instead use two separate test expressions joined by `||`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Valid basic test expressions (sh/bash/ksh)
|
||||||
|
[ x ] || [ y ]
|
||||||
|
|
||||||
|
# Valid extended test expressions (bash/ksh)
|
||||||
|
[[ x ]] || [[ y ]]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
### Related resources:
|
||||||
|
|
||||||
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user