Languages
[Edit]
EN

Bash - for loop with counter

0 points
Created by:
martineau
450

This article will show you how to use for loop with a counter in Bash.

Syntax:

#!/bin/bash

for (( INITIALIZER; CONDITION; STEP))
do
    # commands
done

 

Practical example

#!/bin/bash

for (( i=0; i<5; i++ ))
do  
   echo $i
done

Output:

0
1
2
3
4

Infinite loop

#!/bin/bash

for (( ; ; ))
do  
   echo "Hello"
done

Output:

Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
...

Bash

Bash - for loop with counter
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