mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2244 (markdown)
13
SC2244.md
13
SC2244.md
@@ -31,15 +31,20 @@ fi
|
||||
|
||||
### 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:
|
||||
|
||||
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:
|
||||
|
||||
|
Reference in New Issue
Block a user