Shell Scripting if then elif

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Shell Scripting if then elif

A new if can be nested inside an elif.

Syntax:

Syntax of if then elif is shown in the snapshot below,

Shell scripting If then elif 1

Example if then elif:

We have shown the example of choosing color.

Condition:

  1. if [ $color == Red ]  
  2. elif [ $color == Blue ]  

Shell scripting If then elif 2

Look at the above snapshot, we have shown the script.

Shell scripting If then elif 3

Look at the above snapshot, on Red color it goes to if part, on Blue color it goes to elif part and on other colors it goes to elsepart.