Shell Scripting Tutorial 6

Hello,

I am Aaditya Purani ,If statements (and, closely related, case statements) allow us to make decisions in our Bash scripts. They allow us to decide whether or not to run a piece of code based upon conditions that we may set. If statements, allow us to make much more complex scripts which may solve larger tasks.

Sometimes we want to perform a certain set of actions if a statemen is true, and another set of actions if it is false. We can accommodate this with the else mechanism.

Code:

#!/bin/bash

echo “Hey dude. Which color you like”

read color

if [ $color = “red” ]
then
echo “Correct one man”

elif [ $color = “green” ]
then
echo “Pretty nice guess”

else

echo “Sorry duh”
fi

Advertisements

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