Updated SC2170 (markdown)

Vidar Holen
2021-08-30 20:01:27 -07:00
parent c0a516faf3
commit 86c41d5cb2

@@ -31,13 +31,11 @@ fi
``` ```
### Rationale: ### 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 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)) ]`
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.
### Exceptions: ### Exceptions: