\ Computer \ OS \ *Nix \ Sh \

If else

Shell if tests a condition in [ ]. Spaces inside the brackets are required.

if [ <condition> ]
        then
        ..
elif
        then
        ..
else
fi

elif is else-if. else has no then. The block ends with fi.

Condition

"$var" == "value"

On Ubuntu use = instead of ==.

Numerical

  • -eq
  • -ne
  • -gt
  • -lt
  • -le
  • -ge

String

  • =
  • !=
  • < before alphabetically
  • > after alphabetically
Updated: 2026 Aug 19