-
Notifications
You must be signed in to change notification settings - Fork 9
/
if-else.sh
36 lines (28 loc) · 1.13 KB
/
if-else.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# ------------------------------------------------------------------------------------
# Tutorial: How using if-else work
# ------------------------------------------------------------------------------------
# You can write condition same as in real life
# For example, if the person in front of me is Sarah, I will tell you "Hi Sarah !"
# else, I will tell you "Hi anonymous !"
# In bash, it will be : if my variable person equal Sarah, I will tell you "Hi Sarah !"
# else, I will tell you "Hi anonymous !"
person="Sarah"
# brackets are needed for the condition
if [ $person = "Bob" ]
then
echo "Hi Sarah !"
else
echo "Hi anonymous !"
fi
# if you want to say something if the condition is true but say nothing it's not, you
# don't put the else part, just like this :
if [ $person = "Sarah" ]
then
echo "Hi Sarah !"
fi
# ------------------------------------------------------------------------------------
# Challenge: Say hello !
# ------------------------------------------------------------------------------------
# Write a condition to say Hi to yourself and if it's not your first name
# it will say "No, try again"