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

  3. This is very interesting, You are a very skilled blogger. I have joined your rss feed and look forward to seeking more of your fantastic post. Also, I have shared your web site in my social networks!

    Candace Rocheleau

    June 1, 2020

  4. I’m not sure why but this site is loading incredibly slow for me. Is anyone else having this problem or is it a issue on my end? I’ll check back later on and see if the problem still exists.

    Deane Manjarrez

    June 2, 2020

  5. Magnificent goods from you, man. I’ve understand your stuff previous to and you are just too excellent. I actually like what you’ve acquired here, certainly like what you are stating and the way in which you say it. You make it entertaining and you still take care of to keep it sensible. I cant wait to read far more from you. This is really a terrific site.

    Leonore Donovan

    June 3, 2020

Post a Reply

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