Loops

There are several kinds of loops in a Bourne shell script: for, while, and until.

for loop example:

# The for-loop below prints out the 
# numbers 1 through 5, one number per line.
for i in `seq 1 5`; do
     echo $i
done

while loop example:

# The while-loop below will loop until $i 
# is equal to or greater than $j
while [[ $i -lt $j ]]; do
  echo $i
  let i+=1
done

until loop example:

# The until-loop below is equivalent to the while-loop above
until [[ $i -ge $j ]]; do
  echo $i
  let i+=1
done



Matt Disney 2005-09-14