How to find whether or not a variable is empty in Bash
In Bash at least the following command tests if $var is empty: if [[ -z “$var” ]]; then # Do what you want fi The command man test is your friend.
In Bash at least the following command tests if $var is empty: if [[ -z “$var” ]]; then # Do what you want fi The command man test is your friend.
Both styles are used within the Go’s standard libraries. if len(s) > 0 { … } can be found in the strconv package: http://golang.org/src/pkg/strconv/atoi.go if s != “” { … } can be found in the encoding/json package: http://golang.org/src/pkg/encoding/json/encode.go Both are idiomatic and are clear enough. It is more a matter of personal taste and … Read more
Empty string, undefined, null, … To check for a truthy value: if (strValue) { // strValue was non-empty string, true, 42, Infinity, [], … } To check for a falsy value: if (!strValue) { // strValue was empty string, false, 0, null, undefined, … } Empty string (only!) To check for exactly an empty string, … Read more