O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

18.6. until loop

The until loop lets you execute a series of commands until a condition is true. The until loop is really the opposite of the while loop in its processing. The while loop should always be preferred to the until loop, but in some cases – and it’s only a few – the until loop does the job better.

The format of the until loop is:

until condition   command1  ... done 

The condition is any valid test condition. The test takes place at the end of the loop, therefore it will always loop once – be aware of that please.

Here are a few examples.

18.6.1. Simple until loop

This script continuously greps the who command for the user root. The variable IS_ROOT holds the result of the grep.

If root is found, the loop finishes processing. A ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required