Bash Cases Statement

The case construct in bash shell allows us to test strings against patterns that can contain wild card characters. Bash case statement is the simplest form of the bash if else then condition statement.

The simple example for this is if you are expecting different inputs from a user and want to execute specific command sets on the choice used.



case $variable in

pattern1 )

statements ;;

pattern2 )

statements ;;

* ) statements ;;



We can see the common use of the case statement in the init scripts of the services which has the options like start, stop, restart and status.




  1. Great content! Super high-quality! Keep it up! 🙂


    February 16, 2020

  2. Thanks intended for supplying these kinds of awesome subject matter.


    March 28, 2020

Post a Reply

Your email address will not be published. Required fields are marked *