How to use a FOR loop in BASH

This is a simple example of how to use a FOR loop in bash.
It starts a counter (i) at 100, and increases it by 1 (i+=1) until it reaches 115 (i<=155)
Each time it loops it will echo the value of i and then wait 1 second.

#!/usr/bin/bash
for ((i=100;i<=115;i+=1));
do
   echo $i
   sleep 1
done

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s