-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathForLoopExample.sh
More file actions
executable file
·44 lines (36 loc) · 901 Bytes
/
ForLoopExample.sh
File metadata and controls
executable file
·44 lines (36 loc) · 901 Bytes
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
#!/bin/bash
# Introduction to for-loops. As will be seen in these examples is that they are ideally used when iterating through lists or collections
for i in 1 2 3 4 5
do
echo "Looping ... iteration #$i"
done
# prints:
# Looping ... iteration #1
# Looping ... iteration #2
# Looping ... iteration #3
# Looping ... iteration #4
# Looping ... iteration #5
for file in *
do
echo "Processing $file"
done
for i in hello 1 * 2 goodbye
do
echo "Looping ... i is set to $i"
done
# prints:
# Looping ... i is set to hello
# Looping ... i is set to 1
# Looping ... i is set to ${filename_in_curr_dir}
# Looping ... i is set to 2
# Looping ... i is set to goodbye
for i in hello 1 \* 2 goodbye
do
echo "Looping ... i is set to $i"
done
# prints:
# Looping ... i is set to hello
# Looping ... i is set to 1
# Looping ... i is set to *
# Looping ... i is set to 2
# Looping ... i is set to goodbye