-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_if_statement.sh
executable file
·77 lines (49 loc) · 1.44 KB
/
04_if_statement.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
71
72
73
74
75
76
77
#!/bin/bash
# if statement in Bash Scripting
count=10
if [ $count -gt 20 ]
then
echo "Condition is true"
fi
if (("$count" > 20))
then
echo "Condition is true"
fi
word=abcd
# single equals(=) to also work in comparison of string
if [ $word == "abcde" ]
then
echo "condition is true"
elif [ $word == "abcd" ]
then
echo "Trueeee"
else
echo "Condition is false"
fi
: '
if [condition]
then
statement
fi
1. integer comparison
-eq --> is equal to - if [ "$a" -eq "$b" ]
-ne --> is not equal to - if [ "$a" -ne "$b" ]
-gt --> is greater than if [ "$a" -gt "$b" ]
-ge --> is greater than or equal to - if [ "$a" -ge "$b" ]
-lt --> is less than if [ "$a" -lt "$b" ]
-le --> is less than or equal to - if [ "$a" -le "$b" ]
< --> is less than (("$a" < "$b"))
<= --> is less than or equal to - (("$a" <= "$b"))
> --> is greater than - (("$a" > "$b"))
>= --> is greater than or equal to (("$a" >= "$b"))
2. string comparison
= --> is equal to - if [ "$a" = "$b" ]
== --> is equal to if [ "$a" == "$b" ]
!= --> is not equal to - if [ "$a" != "$b" ]
<- --> is less than, in ASCII alphabetical order - if [[ "$a" < "$b" ]
> --> is greater than, in ASCII alphabetical order - if [[ "$a" > "$b
-z --> string is null, that is, has zero length
Integers --> (< > <= >= ) => Double parenthesis (())
String --> (< > <= >= ) => Double Sq. Brackets [[]]
String --> ( = == !=) => Single Sq. Brackets []
'