While Loop Example Bash
In this example I will be using a while loop.
#!/bin/sh # Guess the number game. Version 2.0 ANSWER=5 # The correct answer echo "Guess a number between 1 and 10. " while read NUM do # Validate the input... if [ "$NUM" -lt 1 ] || [ "$NUM" -gt 10 ]; then echo "The number must be between 1 and 10! Guess again. " elif [ "$NUM" -eq "$ANSWER" ]; then echo "You got the answer correct!" exit else echo "Incorrect, guess again. " fi done
Total Views: 805
My name is Jean-Mathieu
I created this website so other people could enjoy finding useful stuff easier. If you have any question do not hesitate to contact me.
|jean8mathieu||Created on 02/10/15|
Disclosure: We are a website that needs compensation to operate like any other website on the internet.
We may receive consideration for our reviews but we are totally unbiased and do not accept paid reviews or fake reviews claiming to be something they are not.