Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash case statement

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

shell case example

# 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 $'
Do 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)
Comment

bash case statement

case expression in
    pattern1 )
        statements ;;
    pattern2 )
        statements ;;
    ...
esac
Comment

bash case

#!/bin/bash
$web="example.com"
case $web in
 forest.com) echo "It's forest.";;
 animal|human) echo "Maybe animal or maybe human";;
 example.com) echo "This is a site!";;

*) echo $web;;
esac
Comment

PREVIOUS NEXT
Code Example
Shell :: linux custom command 
Shell :: git view stash 
Shell :: git update 
Shell :: Apply .gitignore on an existing repository 
Shell :: git clone command 
Shell :: linux delete files older than specific date 
Shell :: React Hooks Form Installation 
Shell :: bin/sh sam: not found 
Shell :: install nginx in amazon linux 2 
Shell :: give all users access to root folder 
Shell :: linux show alias function 
Shell :: ubuntu update 
Shell :: git view differences between commits 
Shell :: how to install packages from jupyter notebook 
Shell :: bash check length of variable 
Shell :: how to install spark on macos 
Shell :: delete commit from pr 
Shell :: wkhtmltopdf blocked access to file 
Shell :: origin git 
Shell :: download putty for ubuntu 
Shell :: how to get directory size in linux 
Shell :: kubectl commands 
Shell :: keyrings arch linux 
Shell :: restart gnome from terminal 
Shell :: how to print substring in bash script 
Shell :: brave browser install on ubuntu 
Shell :: check network card name linux 
Shell :: git stash with a message 
Shell :: duplicate clone remote branch locally git 
Shell :: Installed Build Tools revision 32.0.0 is corrupted. Remove and install again using the SDK Manager 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =