Posted On December 18, 2020

Bash Shell Quick If Then and Case Switch Statements

kimconnect 0 comments
blog.KimConnect.com >> Codes , Linux >> Bash Shell Quick If Then and Case Switch Statements
protocol=udp # or tcp

# If-then implementation
if [$protocol == udp]
then
	prefix=@
else
	prefix=@@
fi
  
# Case-switch implementation
case "$protocol" in 
    #case 1
    "udp") prefix=@ ;; 
    #case 2
    "tcp") prefix=@@ ;; 
    #case 3 
    "") prefix=@@ ;; 
esac

echo "$prefix"

Leave a Reply

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

Related Post

PowerShell: Function to Confirm Certain Contents

It's always a good idea to receive user confirmations prior on proceeding to making important…

Fedora: Setting Programs to Automatically Start

on a fedora core box, use chkconfig like this:Code:chkconfig --level 345 httpd onchkconfig --level 2345…

Linux: Create a Shell Script to Watch Services

# create a script to watch services (notice the regex escape for special chars) sudo…