Loop trick in bash

For loop in BASH can be written in many ways , it could use a numeric counter
or it could use an array . here are some example that may help :

1. Count up loop in BASH, from 0 to 100

for i in `seq 0 100` ; do echo  $i ;done

2. Countdown loop in BASH , from 100 to 0

for i in `seq 100 -1 0` ; do echo  $i ;done

3. Array variable as increment loop in BASH

ar="one two three four five six eight nine ten"
for i in $ar ;do echo $i ;done

4. Array as increment loop in BASH

for i in one two three four five ;do echo $i ;done
Posted in Tips and Tricks Tagged with: ,