Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • It seems as if the -n test is not needed. If the variable contains no value, it will not be equal to the string null (if that is supposed to be a string at all, sometimes people seems to thing it's a special value that denotes "no value"). Commented Dec 10, 2018 at 18:10
  • @Kusalananda Yeah, I just wrote this for the benefit of the understanding and syntax of the OP, besides being short in time. I also noticed the first condition is redundant. As for the actual string "null", some utilities indeed return "null" as a full string, in specific situations when they have nothing else to return or have not met a condition...jq is one of them, for instance, and in the past I found more doing that. Commented Dec 10, 2018 at 18:46
  • @Kusalananda taken from a script of mine here using jq too: if [ x"$S" == x"null" ] # end of array Commented Dec 10, 2018 at 18:50
  • @Tomaz is incorrect (though I could not find the referenced post). [ is not bash syntax and you cannot use && inside since [ is a command. bash syntax ([[) does support using && and || inside its test operators. Regardless, testing -n has no effect in this particular case Commented Jan 16, 2020 at 20:56