Software >> OS >> Unix >> Shell >> bash >> for loop examples

1.  Loop from 1 to 99 with step of 2

method 1

for ((i=1;i<100;i+=2));do echo $i;done;

method 2

for i in {1..100..2};do echo $i;done;

 

2.  Loop through an integer range

bash

for i in {1..100};do echo $i;done;

sh

for i in $(seq 1 100);do echo $i;done