From 0f1e195b4591b5fe237f6f7bebf230c5a12f689b Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 16 Jan 2019 18:51:18 -0800 Subject: [PATCH] Updated SC2244 (markdown) --- SC2244.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/SC2244.md b/SC2244.md index adc589c..5c0d444 100644 --- a/SC2244.md +++ b/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: