Updated SC2244 (markdown)

Vidar Holen
2019-01-16 18:51:18 -08:00
parent 592175ae27
commit 0f1e195b45

@@ -31,15 +31,20 @@ fi
### Rationale: ### Rationale:
`[ "$var" ]` is equivalent to `[ -n "$var" ]` and checks whether the string is non-empty. `[ "$var" ]` is equivalent to `[ -n "$var" ]` and checks that a string is non-empty.
Users more familiar with other languages are therefore often surprised to learn that `[ "$var" ]` is true when `var=false` or `var=0`. Users more familiar with other languages are often surprised to learn that `[ "$var" ]` is true when:
Adding the explicit `-n` helps clarify that this is a string comparison, and not related to any concept of boolean values or comparisons as it is in most languages. * `var=false`
* `var=0`
* `var=null`
* `var=" "`
Adding the explicit `-n` helps clarify that this is a string comparison, and not related to any concept of boolean values or "truthiness" as it is in most languages.
### Exceptions: ### Exceptions:
If you are familiar with the semantics of `[`, you can [[ignore]] this suggestion with no ill effects. If you are familiar with the semantics of `[`, you can [[ignore]] this stylistic suggestion with no ill effects.
### Related resources: ### Related resources: