How do I go about amending this simple script that prompts for a yes/no response so that if neither Y or N are entered it will loop back back to the original prompt
#!/bin/ksh
echo "Enter yes of no"
read answer
if [ $answer == y -o $answer == Y ]
then
echo "You selected yes"
elif [ $answer == n -o $answer == N ]
then
echo "You selected no"
elif [ $answer != y -o $answer != Y -o $answer != n -o $answer != N ]
then
echo "Invalid Option"
fi
while [ 1 ]
do
echo "Enter yes of no"
read answer
if [ $answer == y -o $answer == Y ]
then
echo "You selected yes"
break
elif [ $answer == n -o $answer == N ]
then
echo "You selected no"
break
elif [ $answer != y -o $answer != Y -o $answer != n -o $answer != N ]
then
echo "Invalid Option. Try again"
fi
done
#!/bin/ksh
echo "Enter yes of no"
read answer
until [ $answer == y -o $answer == Y -o $answer == n -o $answer == N ]
do
echo "Sorry, Please Enter yes of no"
read answer
done
if [ $answer == y -o $answer == Y ]
then
echo "You selected yes"
elif [ $answer == n -o $answer == N ]
then
echo "You selected no"
elif [ $answer != y -o $answer != Y -o $answer != n -o $answer != N ]
then
echo "Invalid Option"
fi
Thanks for the help on this, how would I expand it to prompt for two responses and loop back to the original prompt
i.e.
echo "Enter a choice"
read choice
echo "confirm $choice is correct y/n"
read confirm
if [ $confirm == y -o $confirm == Y ]
then do something
elif [ $confirm == n -o $confirm == N ]
then loop back to the enter a choice prompt
elif [ $confirm != y -o $confirm != Y -o $confirm != n -o $confirm != N ]
then
echo "Invalid Option" and loop back to confirm choice