Multiple choice technology programming languages

Which one is the correct syntax for string comparison ?

  1. if [ "$a" equals "$b" ]
  2. if [ "$a" -eq "$b" ]
  3. if [ "$a" = "$b" ]
  4. if [ "$a" <> "$b" ]
Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In shell scripting, string comparison uses the = operator inside [ ] test brackets. The -eq operator is for numeric comparison only, not strings. The equals keyword is not valid in [ ] test, and <> is not a shell comparison operator.