Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Condensing A loop

Status
Not open for further replies.

inforeqd

Technical User
Jan 8, 2001
95
US
First off, thanks for the earlier responses concerning a discussion for shell scripting.

Now

Heres my question. Bourne shell script with the following

echo "Do you want something (y/n)?"

while true;do
read answer
if [ "$answer" = Y -o "$answer" = y ]
then
DO A COMMAND HERE
break
elif [ "$answer" = N -o "$answer" = n ]
then
echo "Skipping to the next step"
break
fi
done


Any suggestions on shortening this alot. I dont want to repeat it througout a script for everytime I want an answer from a user.

Thanks
Inf
 
Inf,

Looks like a good candidate to put in a function. I'll write it for you if you like (or someone else will) -- do you want that or would you prefer to have a go first? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
I was thnking that. Looks like I'll give it a go, at least I can learn something here.

Thanks
 
Sounds like a good plan <smile>

Don't hesitate to shout if you get stuck. And would you post your solution here as well? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top