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

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 $'
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 switch case

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

bash case statement

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

Bash switch

case "$C" in
"1")
    do_this()
    ;;
"2" | "3")
    do_what_you_are_supposed_to_do()
    ;;
*)
    do_nothing()
    ;;
esac
Comment

bash change case

# Basic syntax:
awk '{print tolower(string)}'
awk '{print toupper(string)}'

# Example usage:
awk '{print tolower($0)}' input_file
# This prints every row ($0) converted to lowercase

awk '{print toupper($3)}' input_file
# This would print the third field ($3) converted to uppercase
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 :: open file in finder from terminals 
Shell :: docker extract file from image 
Shell :: check user group console linux 
Shell :: linux mail delete all 
Shell :: git checkout to remote branch 
Shell :: requiring unknown module "1" 
Shell :: install nodejs debian 10 
Shell :: copy local docker image to kind cluster 
Shell :: prittier download ubuntu 
Shell :: windows show environment variables powershell 
Shell :: install docker on windows powershell 
Shell :: break line bash 
Shell :: rmdir not empty 
Shell :: brew mac 
Shell :: install Fdisk 
Shell :: install brave browser in ubuntu 
Shell :: encrypt zip password 
Shell :: bash for loop multiple statements 
Shell :: Solve Cannot Install Dependency Error for NPM install 
Shell :: vim insert text at the the beginning of multiple lines 
Shell :: install bootstrap in angular 10 
Shell :: commit in git 
Shell :: brew install docker 
Shell :: composer remove packages 
Shell :: run a command with sudo su 
Shell :: shell sort algorithm is an example of? 
Shell :: netstat pid 
Shell :: install scikit learn 
Shell :: git change ssh key 
Shell :: bash check if string starts with substring 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =