-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathifStatement.sh
More file actions
executable file
·54 lines (44 loc) · 1.54 KB
/
ifStatement.sh
File metadata and controls
executable file
·54 lines (44 loc) · 1.54 KB
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
#! /bin/bash
# if [ condition ] # this is how we write an if statement in bash, we must use the square brackets and the condition inside the square brackets
# then # this is how we start the if statement
# echo "This is true"
# fi # this is how we end the if statement
# integer comparison
# -eq - is equal to - if [ "$a" -eq "$b" ]
# -ne - is not equal to - if [ "sa" -ne "sb" ]
# -gt - is greater than - if [ "$a" -gt "$b" ]
# -ge - is greater than or equal to - if [ "sa" -ge "$b" ]
# -It - is less than - if [ "sa" -lt "$b" ]
# -le - is less than or equal to - if [ "sa" -le "sb" ]
# < - is less than - (("$a" < "$b"))
# <= - is less than or equal to - (("sa" < "$b"))
# > - is greater than - (("$a" > "$b"))
# >= - is greater than or equal to - (("$a" >= "$b"))
# # string comparison
# = - is equal to if [ "sa" = "b" ]
# == - is equal to if [ "sa" "$b" ]
# != - is not equal to if [ "$a" != "$b" ]
# < - is less than, in ASCII alphabetical order if [ "sa" < "sb" ]
# > - is greater than, in ASCII alphabetical order if [[ "$a" > "$b
# -z - string is null, that is, has zero length
count=10
if [ $count -eq 10 ] # this is how we compare the integer values
then
echo "This is true"
fi
word=abc
if [ $word == "ab" ] # this is how we compare the string values
then
echo "This is true"
else
echo "This is false"
fi
if [[ $word == "b" ]] # this is how we compare the string values in ASCII alphabetical order
then
echo "This is true"
elif [[ $word > "a" ]] # this is else if statement
then
echo "This is true"
else
echo "This is false"
fi