mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2170 (markdown)
@@ -31,13 +31,11 @@ fi
|
||||
```
|
||||
### Rationale:
|
||||
|
||||
You are comparing a string value with a numerical operator, such as `-eq`, `-ne`, `-lt` or `-gt`.
|
||||
You are comparing a string value with a numerical operator, such as `-eq`, `-ne`, `-lt` or `-gt`. These only work for numbers.
|
||||
|
||||
In `[[ .. ]]`, this would automatically dereference the string, looking to see if there are variables by that name.
|
||||
If you want to compare the value as a string, switch to the equivalent string operator: `=`, `!=` `\<` or `\>`.
|
||||
|
||||
In `[ .. ]`, which you are using, the string is just treated as an invalid number.
|
||||
|
||||
If you want to compare numbers, expand yourself (e.g. use `$var` instead of `var`, or `$((n+1))` instead of `n+1`). If you are trying to compare strings and not numbers, use `=`, `!=` `\<` or `\>` instead.
|
||||
If you want to compare it as a number, such as `n=42; while [ n -gt 1024/8 ]; ..`, then keep the operator and expand the operands yourself with `$var` or `$((expr))`: `while [ "$n" -gt $((1024/8)) ]`
|
||||
|
||||
### Exceptions:
|
||||
|
||||
|
Reference in New Issue
Block a user