Bash Shell scripting – If Statement ( If then fi, If then else fi, If elif else fi)

Bash Shell scripting - If Statement

Bash Shell

Conditional Statements
  • Conditionals let us decide whether to perform an action or not, this decision is taken by evaluating an expression. The most basic form is:



  • the elif (else if) and else sections are optional
  • Put spaces after [ and before ], and around the operators and operands.


  • An expression can be: String comparison, Numeric comparison, File operators and Logical operators and it is represented by [expression]:

Number Comparisons:

  • Examples:

String Comparisons:

  • Examples:

Example Script


Partner Sites