Used in Bash Scripts to compare values with each other.

String Operators

  • ==: Equal to
  • !=: Not equal to
  • <: Less than in ASCII alphabetical order
  • >: Greater than in ASCII alphabetical order
  • -z: The string is empty (null)
  • -n: The string is not null
  • #variable: Number of characters in variable.

Integer Operators

  • -eq: Equal to
  • -ne: Not equal to
  • -lt: Less than
  • -le: Less than or equal to
  • -gt: Greater than
  • -ge: Greater than or equal to

Logical Operators

  • !: Logical NOT
  • &&: Logical AND
  • ||: Logical OR

File Operators

  • -e: if the file exist
  • -f: tests if it is a file
  • -d: tests if it is a directory
  • -L: tests if it is if a symbolic link
  • -N: checks if the file was modified after it was last read
  • -O: if the current user owns the file
  • -G: if the file’s group id matches the current user’s
  • -s: tests if the file has a size greater than 0
  • -r: tests if the file has read permission
  • -w: tests if the file has write permission
  • -x: tests if the file has execute permission

Arithmetic Operators

  • +: Addition
  • -: Subtraction
  • *: Multiplication
  • /: Division
  • %: Modulus
  • variable++: Increase the value of the variable by 1
  • variable--: Decrease the value of the variable by 1

Function Operators

  • ?: The return value of the most recently run function.