SME_Paddington
asked on
Questionnaire bash script for Linux Shell
Dear Experts,
Could you please help me write a questionnaire script, to help test some of our new prospective interns. I will need an end of script echo, as to the result obtained - e.g. how many correct, and incorrect answers; points will be given for percentages too. The script would hopefully take the questions and answers from two separate files, such as: Questions.txt and Answers.txt.
Kind regards, SME_Paddington
My questions, and answers for the two files so far are:
Could you please help me write a questionnaire script, to help test some of our new prospective interns. I will need an end of script echo, as to the result obtained - e.g. how many correct, and incorrect answers; points will be given for percentages too. The script would hopefully take the questions and answers from two separate files, such as: Questions.txt and Answers.txt.
Kind regards, SME_Paddington
My questions, and answers for the two files so far are:
Questions.txt:
1. How many Mb's per second can be transferred over Ethernet?
2. What does FTP stand for?
3. What does IDS stand for?
4. How many bits are there in a byte?
5. What is the 'echo' equivalent in C++?
6. What is the TCP three way hand shake in terms of packets?
Answers.txt:
1. 100mb
2. File Transfer Protocol
3. Intrusion Detection System
4. 8
5. cout
6. SYN SYN-ACK SYN-ACK-ACK
ASKER
Thank you for the correction wesly_chen, but I was ideally looking for an example too.
Kind regards.
Kind regards.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ooops typo, the second sleep should be a lower case s
ASKER
Dear Experts,
I will try your code point_pleasant, but I still need bash.
Is there any way to write this in shell script?
Kind Regards
I will try your code point_pleasant, but I still need bash.
Is there any way to write this in shell script?
Kind Regards
give this a shot same file format for Q&Q as before
exec 4</tmp/QandAfile.txt
tput clear
num_questions=0;
num_correct=0;
echo -n "Enter your name: ";
read name;
while read line
do
num_questions=`expr $num_questions + 1`;
question_number=`echo $line | cut -f1 -d','`;
question=`echo $line | cut -f2 -d','`;
answer_a=`echo $line | cut -f3 -d','`;
answer_b=`echo $line | cut -f4 -d','`;
answer_c=`echo $line | cut -f5 -d','`;
answer_d=`echo $line | cut -f6 -d','`;
correct_answer=`echo $line | cut -f7 -d','`;
tput clear;
echo "Question number $question_number";
echo "$question ?";
echo "a) $answer_a ";
echo "b) $answer_b ";
echo "c) $answer_c ";
echo "d) $answer_d ";
read -p 'Input Selection: ' input_answer < /dev/tty;
if [ "$input_answer" == "$correct_answer" ]
then
num_correct=`expr $num_correct + 1`;
fi
sleep 2;
done < /tmp/QandAfile.txt
echo "Congratulations $name you answered $num_correct questions out of $num_questions"
exec 4</tmp/QandAfile.txt
tput clear
num_questions=0;
num_correct=0;
echo -n "Enter your name: ";
read name;
while read line
do
num_questions=`expr $num_questions + 1`;
question_number=`echo $line | cut -f1 -d','`;
question=`echo $line | cut -f2 -d','`;
answer_a=`echo $line | cut -f3 -d','`;
answer_b=`echo $line | cut -f4 -d','`;
answer_c=`echo $line | cut -f5 -d','`;
answer_d=`echo $line | cut -f6 -d','`;
correct_answer=`echo $line | cut -f7 -d','`;
tput clear;
echo "Question number $question_number";
echo "$question ?";
echo "a) $answer_a ";
echo "b) $answer_b ";
echo "c) $answer_c ";
echo "d) $answer_d ";
read -p 'Input Selection: ' input_answer < /dev/tty;
if [ "$input_answer" == "$correct_answer" ]
then
num_correct=`expr $num_correct + 1`;
fi
sleep 2;
done < /tmp/QandAfile.txt
echo "Congratulations $name you answered $num_correct questions out of $num_questions"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I verify point_pleasant's shell script at
https://www.experts-exchange.com/questions/27033471/Questionnaire-bash-script-for-Linux-Shell.html?anchorAnswerId=35749266#a35749266
with this QandAfile.txt and it works.
I just did some modification based on point_pleasant's script which I don't want the answers in the question file.
https://www.experts-exchange.com/questions/27033471/Questionnaire-bash-script-for-Linux-Shell.html?anchorAnswerId=35749266#a35749266
with this QandAfile.txt and it works.
I just did some modification based on point_pleasant's script which I don't want the answers in the question file.
1, How many Mb's per second can be transferred over Ethernet?,1mb,10mb,100mb,1000mb,b
2, What does FTP stand for?,Fast Transfer Protocol,File Transfer Process,File Transfer Protocol,Font Type Pointer,c
3, What does IDS stand for?,IDentification System,Internet Defending System,Intrusion Detection System,Index Database System,c
4, How many bits are there in a byte?,8,10,16,4,a
5, What is the 'echo' equivalent in C++?,print,cout,printf,reflect,b
ASKER
Dear Experts,
Wesly_chen's solution provides the answer.
I initially required this coding example for two days ago, but it has been moved to this Monday.
I believed that the implementation would not have been properly performed by Monday, as this is when it is required; and thus I did not want to keep open, a question that was essentially (previously) going no-where.
Also, Wesley_chen - excellent implementation, I am very impressed. I believe that multiple solutions should be accepted. Such as post ID: 35758323 and 35747060
As 35758323 is a modification and revision of 35747060.
Kind regards, SME_Paddington
Wesly_chen's solution provides the answer.
I initially required this coding example for two days ago, but it has been moved to this Monday.
I believed that the implementation would not have been properly performed by Monday, as this is when it is required; and thus I did not want to keep open, a question that was essentially (previously) going no-where.
Also, Wesley_chen - excellent implementation, I am very impressed. I believe that multiple solutions should be accepted. Such as post ID: 35758323 and 35747060
As 35758323 is a modification and revision of 35747060.
Kind regards, SME_Paddington
i.e.
Q1. How many Mb's per second can be transferred over Ethernet?
(a) 1mb
(b) 10mb
(c) 100mb
(d) 1000mb
If I type 100MB or 100 MB or 100, which should match your answer sheet but hard for script to parse it.
So make your question in selection will be no error prompt....
By the way, the answer should be (b), because 100mb is Fast Ethernet.....