-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopsExample.txt
More file actions
76 lines (60 loc) · 1.03 KB
/
Copy pathLoopsExample.txt
File metadata and controls
76 lines (60 loc) · 1.03 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Loops!
Loops are very useful, you are able to execute
commands any amount of times.
There are 3 types of loops: Do While, Do Until, and For Loop
Do Until will always execute, then will always execute until false
Do While will only execute when its true, then will always execute until False
For Loop will always execute until its sequence is over,
In While Loops, and Until Loops you can make them Infinite loops
For Loops Can't be infinite and will automatically increment after executing until its done
For Examples:
for i in $( ls )
do
echo $i
done
OUTPUT:
(There are 4 files, FILE1 FILE2 FILE3 FILE4)
FILE1
FILE2
FILE3
FILE4
for i in `seq 1 4`
do
echo $i
done
OUTPUT:
1
2
3
4
Do While Examples
while [ true ]
do
echo Hi
done
^^^^ That is an infinite Loop ^^^^
COUNTER=0
while [ $COUNTER -lt 5 ]
do
echo $COUNTER
COUNTER=$(( COUNTER+1 ))
done
OUTPUT:
0
1
2
3
4
Until Example:
COUNTER=1
until [ $COUNTER -gt 5 ]
do
echo $COUNTER
COUNTER=$(( COUNTER+1 ))
done
OUTPUT:
1
2
3
4
5