mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2107 (markdown)
17
SC2107.md
Normal file
17
SC2107.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
## Instead of [ a && b ], use [ a ] && [ b ].
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
[ "$1" = "-v" && -z "$2" ]
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
[ "$1" = "-v" ] && [ -z "$2" ]
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
`&&` can not be used in a `[ .. ]` test expression. Instead, make two `[ .. ]` expressions and put the `&&` between them.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None.
|
Reference in New Issue
Block a user