1
0
mirror of https://github.com/koalaman/shellcheck.git synced 2025-03-12 12:35:25 -07:00

Created SC1026 (markdown)

koalaman 2018-01-19 19:11:11 -08:00
parent 439ca5570a
commit 8b10bf75e5

30
SC1026.md Normal file

@ -0,0 +1,30 @@
## If grouping expressions inside [[..]], use ( .. ).
### Problematic code:
```sh
[[ [ a || b ] && c ]]
[ [ a -o b ] -a c ]]
```
### Correct code:
```sh
[[ ( a || b ) && c ]]
[ \( a -o b \) -a c ]] # or { [ a ] || [ b ]; } && [ c ]
```
### Rationale:
`[ .. ]` should not be used to group subexpressions inside `[[ .. ]]` or `[ .. ]` statements.
For `[[ .. ]]`, use regular parentheses.
For `[ .. ]`, either use escaped parentheses, or preferably rewrite the expression into multiple `[ .. ]` joined with `&&`, `||` and `{ ..; }` groups.
### Exceptions:
None
### Related resources:
* [Bash Pitfalls: `if [ [ a = b ] && [ c = d ] ]; then ...`](https://mywiki.wooledge.org/BashPitfalls#pf11)