Languages
[Edit]
EN

Bash - for loop in range

0 points
Created by:
Dirask Admin - Marvin
1820

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

Bash

Bash - for loop in range
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join