hi allPls i am new to linux shell scripting and i need to create a phasetest script that displays a set of multiple choice questions similar to an online exam
hi allPls i am new to linux shell scripting and i need to create a phasetest script that displays a set of multiple choice questions similar to an online exam
Hi iykeromison!
If I understand well...You can use "SELECT". This "word" allows you to generate a menu. The sintax is the following:
SELECT [var] IN
[list]
do
statements
done
If you want to do something after that with the correct answer you must use the variable REPLY.
I give you an example:
The result would be like that:Code:PS3='ANSWER?' print 'Select your answer:' select var1 in \ 'Choice a'\ 'Choice b'\ 'Choice c'\ 'Choice d' do case $REPLY in 1) echo "CHOICE: $var1" break ;; *) echo "WRONG" break ;; esac done
Select your answer:
1) Choice a
2) Choice b
3) Choice c
4) Choice d
ANSWER?1
CHOICE: Choice a
I hope it helps you.
There are currently 1 users browsing this thread. (0 members and 1 guests)