MRKAVANA (mrkavana@gmail.com) - www.facebook.com/kavanathai

Jul 18, 2011

How to write a while loop script in bash scripting

This script will work in all linux/unix operating systems like Redhat, Fedora, Centos, Solaris, Ubuntu, Debian etc, if they are having bash shell or sh.
The syntax is as follows :
while [ "$Condition_variable1" operation "$Condition_variable2" ]
do
    commands to execute
done
The thing to note is "$Condition_variable1" should be less than "$Condition_variable12" here in this example.

See the example given below :

#!/bin/bash
#Purpose : To test the while loop
MIN=0
MAX=10
while [ "$MIN" -lt "$MAX" ]
do
        echo $MIN
        let "MIN += 1"
done




No comments:

Post a Comment