Receive all updates via Facebook. Just Click the Like Button Below

Case Statement

The case statement can be used to match several values against one variable.
The case statement is very useful when you want to provide options for the users.

Select 1 to say " Hello "
Select 2 to say " Good Bye "


Case Statement in Linux Shell Scripting



case  $variable-name  in
	pattern1)  { code to execute };;
	pattern2)  { code to execute };;
	patternN)  { code to execute };;
	{ code to execute };;


# Get the value from the user
echo "Enter a digit between [ 1 and 4 ]"
echo "Enter a value for the variable x:"
read x

case $x in
   "1") echo "You have entered One";;
   "2") echo "You have entered Two";;
   "3") echo "You have entered Three";;
   "4") echo "You have entered Four";;
   *) echo "Sorry, You have entered a value beyond limit";;


Enter a digit between [ 1 and 4 ]
Enter a value for the variable x:
You have entered Four

The script takes the value for x from the user and process it accordingly.
In the above example, we entered 4 as the value of x. Try this example script with various other values and see the results. Also try adding more options to the case statement.


Related posts:

Advertise here

picture picture

Follow us


- Tech-Tutorials

Like us

About Techcuriosity

I am Telson, the webmaster of and through this site, I share my knowledge and curiosities in the Tech World.

What We Offer

  • What is ..?
  • How to ..?
  • Difference between ..?
  • How .. works?
  • Get in Touch
    UK : +44 77 33 890 678

    picture picture

    Our Partners

  • Website Design Dubai
  • SEO Link Exchange
  • picture