The
case..esac construct allows to execute an operation according to the value assumed by a variable.
The structure is:
case $control_variable in
0) code0
;;
1) code1
;;
2) code2
;;
esac
If the variable assumes the value 0, the
codice0 is executed; if the variable assumes the value 1, the
code1 is executed, etc.
Here is an example:
#!/bin/bash
x=5
case $x in
0) echo "Value of x: 0"
;;
5) echo "Value of x: 5"
;;
9) echo "Value of x: 9"
;;
esac