I needed a quick loop to count odd then even numbers in bash.

In this example I want to call a script called “script.sh” with an argument of an odd number from 1037 to 1059 recursively.

for (( i=1037; i<=1059; i=i+2 ))
do
  script.sh $i
done

Obviously, for even numbers, start with an even number

for (( i=1038; i<=1059; i=i+2 ))
do
  script.sh $i
done

About troyski

I'm a freelance UNIX engineer working in the UK. I'm married to Tina and between us we have six children. I'm a bit of an Apple fan boy, and all the Windows machines in the house are a thing of the past now.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Post navigation