-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.sh
121 lines (96 loc) · 2.13 KB
/
main.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
#! Varible
NAME="Thoriq AS"
UMUR=18
echo "Nama saya $NAME umur $UMUR"
#! Array
NAME[0]="Zara"
NAME[1]="Qadir"
NAME[2]="Mahnaz"
NAME[3]="Ayan"
NAME[4]="Daisy"
echo "First Index: ${NAME[0]}"
echo "Second Index: ${NAME[1]}"
echo "First Method: ${NAME[*]}"
#! Arithmetic Operators
echo $((2 + 3 - (1 * 3)))
echo 2 + 10 | bc
expr 100 - 3
((x = 2, y = 3, a = x + y, b = x * y, c = x ** y))
echo $a, $b, $c
#! Relational Operators
# -eq = equal , -ne = not equal , -gt = greater than , -lt = less than
# -ge = greter equal , -le = less equal
#! Codition
CUSTOMER="Thoriq AS"
BATAS=18
if [ $UMUR -ge $BATAS ]; then
echo "Boleh Masuk $CUSTOMER"
else
echo "Gak Boleh masuk umur anda $UMUR"
fi
if [[ $UID -eq 0 ]]; then
echo "You are root!"
elif [[ $UID -eq 1002 ]]; then
echo "You are user, welcome!"
else
echo "You are not welcome here."
# exit 1
fi
#! Take Input and Another Example Using Relation & Boolean Opeators
# Reading data from the user
# read -p 'Enter number 1 : ' NUMBER1
# read -p 'Enter number 2: ' NUMBER2
# if (($NUMBER1 == $NUMBER2)); then
# echo a is equal to b.
# else
# echo a is not equal to b.
# fi
# if (($NUMBER1 <= $NUMBER2)); then
# echo a is less than or equal to b.
# else
# echo a is not less than or equal to b.
# fi
# if (($NUMBER1 >= $NUMBER2)); then
# echo a is greater than or equal to b.
# else
# echo a is not greater than or equal to b.
# fi
# if (($NUMBER1 == "true" & $NUMBER2 == "true")); then
# echo Both are true.
# else
# echo Both are not true.
# fi
# if (($NUMBER1 == "true" || $NUMBER2 == "true")); then
# echo Atleast one of them is true.
# else
# echo None of them is true.
# fi
# if ((!$NUMBER1 == "true")); then
# echo "a" was initially false.
# else
# echo "a" was initially true.
# fi
#! Loop
for i in 0 1 2 3 4 5; do
echo "Element $i"
done
for i in {0..10}; do
echo "Element $i"
done
# For loop C-style
for ((i = 0; i <= 5; i++)); do
echo "Element $i"
done
NUMBER=0
while [ $NUMBER -lt 1 ]; do
echo $NUMBER
if [ $NUMBER -eq -5 ]; then
break
fi
# a=$(($NUMBER + 1))
NUMBER=$(expr $NUMBER - 1)
done
for i in "${NAME[@]}"; do
echo "Element $i"
done