Shell Scripting Tutorial 6


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.



echo “Hey dude. Which color you like”

read color

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

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


echo “Sorry duh”


Leave a Reply

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

You are commenting using your 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 )

Connecting to %s