[Next] [Previous] [Up] [Top] [Contents]

9.9.4 while

9.9.4.1 Sh

while condition

do

command list

[break]

[continue]

done

A simple script to illustrate a while loop is:

#!/bin/sh

while [ $# -gt 0 ]

do

echo $1

shift

done

This script takes the list of arguments, echoes the first one, then shifts the list to the left, losing the original first entry. It loops through until it has shifted all the arguments off the argument list.

$ ./while.sh one two three

one

two

three


Introduction to Unix - 14 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]