Languages
[Edit]
EN

Bash - for loop in range

0 points
Created by:
Wade
562

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
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

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