TheTAZZone - Internet Chaos

Shell scripting

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
#!/bin/sh

echo -en “Please pick a number between 1 and 9:”
read number
echo “You have chose “$number”, is this correct (Yes or No)?”
read answer

#If the answer is no, ask for the number to be re-entered and re-validate the input

while [ “$answer” == “No” ]
do
echo -en “Please re-enter your number:”
read number
echo -en “Is this your number: “$number”? (Yes or No):”
read answer

done

# Once the answer is Yes, then carry on with the script

if [ “$answer” == “Yes” ]; then
echo “Ok, please wait whilst I consult my database…”

sleep 1
echo “.”
sleep 1
echo “..”
sleep 1
echo “…”
sleep 3;
echo “OK, database consulted, lets see if you won”

sleep 5
echo “.”
sleep 1
echo “..”

if [ “$number” != “3” ]; then
echo “Unlucky, that is not the magic number”

else

if [ “$number” == “3” ]; then
echo “Well done, you guessed it!”
fi
fi
fi

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

N

Leave a Reply

Your email address will not be published. Required fields are marked *

Advertise

If you'd like to advertise on The Mutt ( aka TheTAZZone.com ) feel free to contact us at: administration[at]thetazzone.com

TheTAZZone is a non-commercial entity. We do not sell any products or services ourselves. Our revenue comes from advertising and donations only.

We appreciate your support! Your advertising revenue ( or donations ) helps us to continue to upgrade, improve, and offset the costs of maintaining this site.

Donations can be made through the page ' Donate '.