While Loop

While Loop
The while loop will continue until a specific requirement is met.  As long as the exit status is zero, the commands will loop down until the done is reached and loop back through.  Exit will occur when a nonzero occurs.

Lesson 12 | Lesson 14

In the following script, as long as the user does not type Colts the script will loop forever.  

The variable must be declared to be able to function that way you want, so this line starts with the variable "Rams", which really does nothing but help you declare the value of the variable.


The "!" is the same as saying not.  So this line tells the script that as long as the input is not Colts it should continue.

while [ "$INPUT_STRING" != "Colts" ]

The read INPUT_STRING will take the input placed on the command line and check that input against the "Colts" line.

while [ "$INPUT_STRING" != "Colts" ]
echo "What is the best football team (Type Colts to quit)"
echo "You guessed: $INPUT_STRING"



Copyright CyberMontana Inc. and BeginLinux.com
All rights reserved. Cannot be reproduced without written permission. Box 1262 Trout Creek, MT 59874