LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   another help with scripting?! (https://www.linuxquestions.org/questions/programming-9/another-help-with-scripting-351121/)

ice99 08-08-2005 09:15 AM

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))???

satinet 08-08-2005 09:28 AM

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

urka58 08-09-2005 09:56 AM

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


All times are GMT -5. The time now is 10:19 PM.