-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_19_for_loop.sh
More file actions
72 lines (52 loc) · 1.11 KB
/
tutorial_19_for_loop.sh
File metadata and controls
72 lines (52 loc) · 1.11 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
#! /bin/bash
# For loop:
#Syntax 1:
# for VARIABLE in 1 2 3 4 5 ... n
# do
# command1
# command2
# command3
# done
#Example
for i in 1 2 3 4 5
do
echo $i
done
# it will print (1 2 3 4 5)
echo "................................................"
for i in {1..10} # for runing loop in range
do
echo $i
done
echo "................................................"
for i in {1..10..2} # 1 is starting point, 10 is ending point and after 2nd two dot 2 is for incrementing starting point
do #start..end..increment
echo $i
done
echo "................................................"
#Syntax 2: can use files as inputs also
# for VARIABLE in file1 file2 file3
# do
# command1 on $VARIABLE
# command2
# command3
# done
# #Syntax 3: can use commands as input also
# for OUTPUT in $(Linux-Or-Unix-Command-Here)
# do
# command1 on $OUTPUT
# command2 on $OUTPUT
# commandN
# done
#Syntax 4: (Similar to C/C++ programming)
# for (( EXP1; EXP2; EXP3 ))
# do
# command1
# command2
# command3
# done
#Example
for (( i=0; i<5; i++ ))
do
echo $i
done