LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-08-2005, 08:15 AM   #1
ice99
Member
 
Registered: Aug 2005
Posts: 51

Rep: Reputation: 15
another help with scripting?!


in my script i need to have only 2 answers, YES and NO. and if someone answer something else i heed to tell him that answers are only YES and NO and no others and to redirect him again to the same question.

example

echo -n "Do you want to make a new copy (yes/no)"
(if YES then continue) (if NO again continue) ( if something else "answer only with YES or NO Do you want to make a new copy (yes/no))???
 
Old 08-08-2005, 08:28 AM   #2
satinet
Senior Member
 
Registered: Feb 2004
Location: England
Distribution: Slackware 14.2
Posts: 1,491

Rep: Reputation: 50
This works for me - asking a question to confirm whether to proceed or not in a script....


echo "\n"
echo "LAST chance to back out"
echo "Are the detail correct?"
read Answer

while [ $Answer != 'n' ] && [ $Answer != 'y' ]
do
echo "Please press y or no and press enter"
read Answer
done
 
Old 08-09-2005, 08:56 AM   #3
urka58
Member
 
Registered: Nov 2003
Distribution: slackware 14
Posts: 543

Rep: Reputation: 43
For the purpose <case> could be a good solution

echo -n "Do you want to make a new copy (yes/no)"
read i
case $i in
Y|y|yes|YES)
/usr/bin/cp /path/to/source /path/to/dest
;;
N|n|no|NO)
exit
;;
*)
echo "Possible answers are only yes or no"
exit
;;
esac

this is for a simple task script.
If other actions follow, it could be useful using some functions
Hope this helps
Ciao
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
new to scripting mifan Linux - Newbie 2 08-17-2005 12:10 PM
Need help scripting Tamara Programming 7 06-06-2005 02:06 AM
Scripting Help Please Jazinator Linux - Newbie 7 10-17-2004 06:35 PM
scripting bforest Linux - Newbie 4 05-11-2004 02:45 AM
scripting anjiie Linux - Newbie 1 02-16-2004 08:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration