-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathloops.sh
More file actions
executable file
·59 lines (44 loc) · 1.08 KB
/
Copy pathloops.sh
File metadata and controls
executable file
·59 lines (44 loc) · 1.08 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
55
56
57
58
59
#!/usr/bin/env bash
## Globals variables
seperator="---------------------------------------------------"
## Better output visualisation.
echo "$seperator"
#####################
# for Loop
#####################
## for loop simple version
for i in 1 2 3 4 5; do
echo "Iteration number $i using for loop simple version"
done
echo "$seperator"
## for Loop using a range
for i in {1..5}; do
echo "Iteration number $i using for loop with range."
done
echo "$seperator"
## for Loop using a bash array
bash_array=(1 2 3 4 5 )
for i in "${bash_array[@]}"; do
echo "Iteration number $i using for loop with bash array."
done
echo "$seperator"
#####################
# while Loop
#####################
# print count as long as it is less than or equal to 5
count=1
while [ $count -le 5 ]; do
echo "Count is $count using while loop"
((count++))
done
echo "$seperator"
#####################
# until Loop
#####################
# print count as long as it is not greater than to 5
count=1
until [ $count -gt 5 ]; do
echo "Count is $count using until loop"
((count++))
done
echo "$seperator"