Hey Guys.
I need to code a series of menus that have four options, selectable either by the number in the menu or the name, in succession. This part I have achieved however I am struggling to find a way that should the user try to enter an invalid selection, such as the number 5 or an incorrect name, there is an echo line saying that the entry is incorrect and the menu presented again - this will happen until a correct selection is made.
I have managed to get the echo line working: "echo "Chosen option is unknown, please try again!"\\n" .
As you can see, there are three menus at present.
One asks you to select from a list of friends whose names you previously input.
The next asks you to choose a celebrity from a precoded list.
The next asks you to choose a file from a precoded list.
This is my first time working with the korn shell and I first though of gotos (if incorrect, goto line whatever) but they unfortunatly dont work
read VarName?"Please enter your name, then press Enter and Ctrl+D: "
echo "Hello, Welcome $VarName !" \\n
echo "Please enter your friends' names, seperated by spaces: " \\n
read VarFriend1 VarFriend2 VarFriend3
echo "Please choose a friend from the given menu below: "
select VarFriends in $VarFriend1 $VarFriend2 $VarFriend3 Exit
do
if [[ -z "$VarFriends" ]]
then
echo "Chosen option is unknown, please try again!"\\n
else
echo "You choose $VarFriends"\\n
fi
if [[ $VarFriends = Exit ]]
then exit
else
echo "Welcome $VarFriends"\\n
fi
break
done
echo "Please choose a celebrity from the given menu below: "
select VarCeleb in RickRoss Eminem Obama Exit
do
if [[ -z "$VarCeleb" ]]
then
echo "Chosen option is unknown, please try again!"\\n
else
echo "You choose $VarCeleb"\\n
fi
if [[ $VarCeleb = Exit ]]
then exit
else
echo "Welcome $VarCeleb"\\n
fi
break
done
echo "Please choose a File, A, B, or C which may correspond to the chosen Celebrity below: "
select VarFiles in FileA FileB FileC Exit
do
if [[ -z "$VarFiles" ]]
then
echo "Chosen option is unknown, please try again!"\\n
else
echo "You choose $VarFiles"\\n
grep $VarCeleb $VarFiles
fi
if [[ $VarFiles = Exit ]]
then exit
else
echo "This is $VarFiles"\\n
cat $VarFiles
fi
done
Any help would be greatly appreciated! I've been scratching my head all night about it, the answer is probably staring me in the face haha.
Thanks for all your help in advance,
Mudja