Horje
bash case statement Code Example
case $var in
	pattern1)
    	#code
        ;;
    pattern2|pattern3)
    	#code
        ;;
    *)
    	#code
        ;;
esac
bash case statement
case "$1" in
        start)
            start ;;
        stop)
            stop ;;
        restart)
            stop; start ;;
        *)
            echo $"Usage: $0 {start|stop|restart}"
            exit 1
esac
Source: tldp.org
bash case statement
# Basic syntax:
case "STRING" in
	patterns)
		echo "commands to perform if patterns matched STRING"  
        ;;
	to)
        echo "commands to perform if to matched STRING" 
        ;;
    search)
        echo "commands to perform if search matched STRING" 
        ;;
    *)
        echo "anything that wasn't matched by the previous patterns"
        exit 1
        ;;
esac

# Example usage:
# If you want to write a bash script where you ask the user how to proceed, you
#	could do something like this:
read -r -p $'\nDo you want to perform this action? (y/n/q): ' RESPONSE
	case $RESPONSE in
    	[Yy]*)
        	echo "The user chose y"
        	;;
        [Nn]*)
        	echo "The user chose n"
            ;;
        [Qq]*)
        	echo "The user chose q, script aborted"
            exit 0
            ;;
        *)
        	echo "The user chose something other than y, n, or q"
            ;;
	esac
# Note, the patterns like [Yy]* will match the string in $RESPONSE if that
#	string starts with Y or y followed by any number of other characters. So
#	it would also match Yes, yes, yertyujiwjwijdwi, etc
# Note, if you want this message to keep repeating until the user types q, put
#	the above in a while loop that never ends (e.g. while true; do ... done)
Source: linuxize.com




Shell

Related
how do i clone a specific branch in git Code Example how do i clone a specific branch in git Code Example
save output of command to craible bash Code Example save output of command to craible bash Code Example
powershell Foreach Code Example powershell Foreach Code Example
how to install pygame Code Example how to install pygame Code Example
awk if else statement Code Example awk if else statement Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12