diff --git a/SC2170.md b/SC2170.md index 62fc72e..96f9e0b 100644 --- a/SC2170.md +++ b/SC2170.md @@ -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: