Monday, March 28, 2011

How to write a until loop script in bash scripting

Sponsored Links
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 :
until [ "$Condition_variable1" operation "$Condition_variable2" ]
do
    commands to execute
done
The thing to note is "$Condition_variable1" should be greater than "$Condition_variable12" here in this example.

See the example given below :

#!/bin/bash
NUM=10
MIN=5
until [ "$NUM" -eq "$MIN" ]
do
        echo $NUM
        let "NUM -= 1"
done
Sponsored Links

No comments:

Post a Comment

Be nice. That's all.