📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store
  • ✖

      Question

      In a POSIX shell script, which construct correctly tests

      whether variable x is an empty string?
      A if [ $x -eq "" ] Correct Answer Incorrect Answer
      B if [ -z "$x" ] Correct Answer Incorrect Answer
      C if (($x == "")) Correct Answer Incorrect Answer
      D if test -n $x Correct Answer Incorrect Answer
      E if expr $x = "" Correct Answer Incorrect Answer

      Solution

       -z returns true if string length is zero; quoting $x avoids word-splitting when empty.

      Practice Next
      ask-question