EN
Bash - for loop in range
0 points
This article will show you how to use for loop in range in Bash.
Syntax:
xxxxxxxxxx
1
2
3
for variable in {START..END..STEP}
4
do
5
# We refer to the current value of the variable by $variable
6
done
Note:
If you don't give a step and just write
{START..STOP}
, the default value of the step is 1.
xxxxxxxxxx
1
2
3
for number in {1..5}
4
do
5
echo $number
6
done
Output:
xxxxxxxxxx
1
1
2
2
3
3
4
4
5
5
xxxxxxxxxx
1
2
3
for number in {0..20..4}
4
do
5
echo $number
6
done
Output:
xxxxxxxxxx
1
0
2
4
3
8
4
12
5
16
6
20