echo "Please enter your first name: \c"
read firstname
echo "Please enter your last name: \c"
read lastname
echo "Your name is $firstname $lastname. Is that correct?"
select BOOLEAN in Yes No
do
if [[ -z "$BOOLEAN" ]]
then
echo "Incorrect choice. Choose again!"
else
echo "Welcome $firstname $lastname"
break
fi
done
My problem is that when it comes to the choosing 'Yes' or 'No', if I select NO, the code will continue as if I selected YES. However, if I select NO, I want the code to keep asking the user to retype their name until they say YES.
firstname=""
lastname=""
enter()
{
echo "Please enter your first name: \c"
read firstname
echo "Please enter your last name: \c"
read lastname
export lastname
export firstname
}
while true
do
enter
echo "Your name is $firstname $lastname. Is that correct?"
read BOOLEAN
if [[ -z "$BOOLEAN" ]]
then
echo "Incorrect choice. Choose again!"
continue
fi
if [[ "$BOOLEAN" = "No" ]] ; then
continue
fi
done
# you get here when okay
echo "Welcome $firstname $lastname"
This looks like homework, so I am not going to give you an answer, but since you at least try to come up with a script, I'll give you a pointer.
Look into "while" loops, as in "while $ANSWER equals no, keep asking the questions". Any response other than "no" will break the loop. Look into the man pages for your shell.