mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2130 (markdown)
19
SC2130.md
Normal file
19
SC2130.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
## -eq is for integer comparisons. Use = instead.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
[[ $foo -eq "Y" ]]
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
[[ $foo = "Y" ]]
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
Shells have two sets of comparison operators: for integers (`-eq`, `-gt`, ...) and strings (`=`, `>`, ...). ShellCheck has noticed that you're using an integer comparison with string data.
|
||||||
|
|
||||||
|
If you are in fact comparing integers, double check your parameters. Certain mistakes like `$$foo` or `${bar}}` can introduce non-numeric characters into otherwise numeric arguments.
|
||||||
|
|
||||||
|
### Contraindications
|
||||||
|
|
||||||
|
None.
|
Reference in New Issue
Block a user