Case statement in bash

In this article let’s discuss about Case statement in bash . Let’s go through the following methods without any delay.

Method 1:

case "$1" in
        start)
            start ;;
        stop)
            stop ;;
        restart)
            stop; start ;;
        *)
            echo $"Usage: $0 {start|stop|restart}"
            exit 1
esac

If you are facing any issues with the above approach then try the alternative that is given below. It may look similar by have a try!

Method 2 :

case $1 in
start)
    #Start logic
    ;;
stop)
    # Stop logic
    ;;
*)
	# Default logic
    echo $"Usage: $0 {start|stop}"
    exit 1
    ;;
esac

Hope the above solution works.

Realted Posts : How to install aws cli mac