Until loop in shell script

Until loop is opposite to while loop.

It will execute the loop as long as condition false.


When condition meet true it will terminate from the loop.


script:
#!/bin/bash

var=0
until [ $var -eq 5 ]
do
    echo "loop $var"
    var=$(( $var +1 ))
done

output:
loop 0
loop 1
loop 2
loop 3
loop 4

Conclusion:

Above script shows as long as 'var' reach 5 condition fails so until execute the loop. When 'var' reaches 5 condition become true so it come out of loop.

 

No comments:

Post a Comment