Skip to content

emka.web.id

Menu
  • Home
  • Indeks Artikel
  • Tutorial
  • Tentang Kami
Menu

Belajar Bash: Until Loop

Posted on July 22, 2012 by Syauqi Wiryahasana
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. #!/bin/bash i=0 until [ $i -eq 100 ] do echo $i i=$(( $i +1 )) done 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. #!/bin/bash COUNTER=200 until [  $COUNTER -lt 9 ]; do echo COUNTER $COUNTER let COUNTER-=1 done  
Seedbacklink

Recent Posts

TENTANG EMKA.WEB>ID

EMKA.WEB.ID adalah blog seputar teknologi informasi, edukasi dan ke-NU-an yang hadir sejak tahun 2011. Kontak: kontak@emka.web.id.

©2024 emka.web.id Proudly powered by wpStatically