Simple Bash Scripting – Case Statement

Angry-bird-red-toy For the RHCE test you are probably going to want to know how to write a simple bash script which employs a simple case statement.

Note that the ")" symbol is used to separate the list of selections from the action to be taken. Fall through is done using *, which catches all input that has not been specificed previously. Also ;; acts as a case break.

Note that the statement is started with “case” and closed with “esac

#!/bin/bash
    case "$1" in
this)  echo "this"
;;
that) echo "that"
;;
*) echo "Type this or that" 
esac

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s