Belajar Bash: Until Loop

The until loop will continue until a specific requirement is met or  as long as the exit status is NOT zero.  This is the opposite of the while loop.

In the example below you can see that the variable “i” starts with 0 and will loop until it equals 100.  It is incremented by one each loop.  When it reaches 100 it will deliver the zero as an indication of success and the loop will stop.

until [ $i -eq 100 ]
echo $i
i=$(( $i +1 ))

Here is the opposite script counting down from 200.  This script counts down until the number is less than 9.  Note that let is used with a negative number.

until [  $COUNTER -lt 9 ];
let COUNTER-=1


Wagiman Wiryosukiro

Petani Sistem Informasi, tukang las plugin & themes Wordpress. Co-Founder Saat ini aktif sebagai Developer & kontributor di OpenMandriva Linux.

You may also like...

Leave a Reply

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

%d bloggers like this: