What is Case?

case…esac Conditional construct statement- It is used to check for multiple conditions for a decision making process in a shell script.

Syntax


		
case $variable_name in
			case1_pattern)
				<commands>
			;;
			case2_pattern)
				<commands>
			;;
			case3_pattern)
				<commands>
			;;
			.
			.
			*)						//default_case
				<commands>
			;;
			esac

		

Example of Case in Shell Scripting


		
#!/bin/bash
read –p “Enter a character:”  char
case $char in 
[a-z])
echo “ You have entered a lower case alphabet”
;;
[A-Z])
echo “ You have entered an upper case alphabet”
;;

[0-9])
echo “ You have entered a digit”
;;

?)
echo “ You have entered some other special character”
;;

*)
echo “ You have entered more than one character”
;;
esac