-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_5_If_stetement.sh
More file actions
41 lines (32 loc) · 877 Bytes
/
tutorial_5_If_stetement.sh
File metadata and controls
41 lines (32 loc) · 877 Bytes
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
37
38
#! /bin/bash
#if statement is used to check some condititons if evaluation of condition is true then block of code which is in if statement block will execute else else block's code will execute(or if block's code will not execute)
#syntax:
#if [condition] #note that space between 'if' and [] is necessary
#then
# statement
#fi #'fi' is for end of the if block's code
count=10
if [ $count -eq 9 ] #'-eq' is used to check equality just like '==' in any other programming language
then
echo "condition is true"
fi
#using else
if [ $count -eq 9 ]
then
echo 'condition is true'
else
echo 'condition is not true'
fi
#example for else if
if [ $count -eq 9 ]
then
echo 'condition is true'
elif [ $count -gt 4 ]
then
echo 'count is greater than 4'
elif [ $count -gt 12 ]
then
echo 'count is greater than 12'
else
echo 'condition is false'
fi