mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2077 (markdown)
21
SC2077.md
Normal file
21
SC2077.md
Normal file
@@ -0,0 +1,21 @@
|
||||
## You need spaces around the comparison operator.
|
||||
|
||||
### Problematic code:
|
||||
|
||||
[[ 0=1 ]]
|
||||
|
||||
### Correct code:
|
||||
|
||||
[[ 0 = 1 ]]
|
||||
|
||||
### Rationale:
|
||||
|
||||
`[[ 0 = 1 ]]` means "check if 0 and 1 are equal".
|
||||
|
||||
`[[ str ]]` is short form for `[[ -n str ]]`, and means "check if `str` is non-empty". It doesn't matter if `str` happens to contain `0=1`.
|
||||
|
||||
Always use spaces around the comparison operator in `[..]` and `[[..]]`, otherwise it won't be recognized as an operator.
|
||||
|
||||
### Contraindications
|
||||
|
||||
None.
|
Reference in New Issue
Block a user