-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathif-else.sh
70 lines (63 loc) · 815 Bytes
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
#make sure spaces of square brackets in if statement
#variable string/text
echo "sample 1:"
continue=yes
if [ $continue == yes ]
then
echo "yes"
else
echo "no"
fi
#variable digit
echo "sample 2:"
z=10
if [ $z == 10 ]
then
echo "Value is 10"
else
echo "Values is not equal to 10"
fi
#Check empty var
echo "sample 3:"
x=
if [ -z "$x" ]
then
echo "Value is empty"
else
echo "Values is $z"
fi
#between two variable
echo "sample 4:"
z=17
e=17
if [ $z == $e ]
then
echo "Equal"
else
echo "Not equal"
fi
#if-else ladder
echo "sample 5:"
z=17
e=27
if [ $z == 1 ]
then
echo $z
elif [ $e == 27 ]
then
echo $e
fi
#nested if-else
echo "sample 6:"
z=17
e=27
if [ $z == 16 ]
then
if [ $e == 26 ]
then
echo "hello z e"
fi
else
echo "oh z e"
fi