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