Case Statement in Shell Script:
In shell script case statement is similar to switch statement in C. The case statement allows you to easily check pattern (conditions) and then process a command-line if that condition evaluates to true.
Syntax of bash case statement:
case expression in pattern1 ) statements ;; pattern2 ) statements ;; ... esac
Example:
#!/bin/bash echo -n "Are you a linuxfunda reader? [Yes or No]: " read answer case $answer in [yY] | [yY][Ee][Ss] ) echo "Great Have fun with new how to guides!" ;; [nN] | [nN][Oo] ) echo "You should read the posts. These are excellent."; exit 1 ;; *) echo "Please Enter a valid input: [Yes or No]" ;; esac