ORIGINALLY POSTED BY HARRY FOR THETAZZONE/TAZFORUM HERE
Do not use, republish, in whole or in part, without the consent of the Author. TheTAZZone policy is that Authors retain the rights to the work they submit and/or post…we do not sell, publish, transmit, or have the right to give permission for such…TheTAZZone merely retains the right to use, retain, and publish submitted work within it’s Network
Please refer to the original post as not all the script may be visible here.
Well, the time has come for me to have to learn shell scripting, all my efforts have gone into BAT and VBS scripting so far but I can’t avoid having to learn it now.
I started yesterday googleing a few sites and came across some very useful tutorials.
Today I decided to give it a go and create a small but useless shell script from scratch and see how it goes.
I wanted something that checks user input, validates it, and acts according to the input it receives. It’s for no special purpose just to act as a marker to see where I am up to.
I’m competent in C and fairly decent in Python but shell scripting seems to have a large amount of subtle differences.
I came up with this:
- Code: Select all
echo -en “Please pick a number between 1 and 9:”
echo “You have chose “$number”, is this correct (Yes or No)?”
#If the answer is no, ask for the number to be re-entered and re-validate the input
while [ “$answer” == “No” ]
echo -en “Please re-enter your number:”
echo -en “Is this your number: “$number”? (Yes or No):”
# Once the answer is Yes, then carry on with the script
if [ “$answer” == “Yes” ]; then
echo “Ok, please wait whilst I consult my database…”
echo “OK, database consulted, lets see if you won”
if [ “$number” != “3” ]; then
echo “Unlucky, that is not the magic number”
if [ “$number” == “3” ]; then
echo “Well done, you guessed it!”
What I can’t seem to do is to stop the damn thing exiting after it has completed. I want it to run until ^C is hit.
Does anyone have any ideas?
Thanks very much