In: Computer Science
Write a shell script of the following: “A Multiple Choice Question that contains 5 questions and each question carries 2 options. Choice will be given by the students. A record file is created each time the script runs to store the answers along with the total marks obtained. The record filename that has date and timing information as well as the student name.
#!/bin/bash # GNU bash, version 4.3.46 echo "Enter your name" read n now=$(date +"%T") echo "Answe Time : $now" echo "Student Details : -" >>temp echo "STUDENT NAME : $n" >> temp echo "Start time : $now" >> temp mark echo -e "Question no 1 : \n=====================================" echo "What is the value of 2+2" echo "a.4 b.0" read k if test "$k" = "a" then #echo "right ans" mark=`expr $mark + 10` echo "question 1 ans is : a.4 " >>temp else #echo "wrong ans" echo "question 2 ans is : b.0 " >>temp fi echo "====================================" echo -e "Question no 2 : \n=====================================" echo "does a bird fly" echo "a.Yes b.No" read k if test "$k" = "a" then #echo "right ans" echo "question 2 ans is : a.yes " >>temp mark=`expr $mark + 10` else #echo "wrong ans" echo "question 2 ans is : b.no " >>temp fi echo "====================================" echo -e "Question no 3 : \n=====================================" echo "what is the value of 1/0" echo "a.1 b.Error" read k if test "$k" = "b" then #echo "right ans" mark=`expr $mark + 10` echo "question 3 ans is : b.Error" >>temp else #echo "wrong ans" echo "question 3 ans is : a.1 " >>temp fi echo "====================================" echo -e "Question no 4 : \n=====================================" echo "what is the value of root 3*3*3*3" echo "a.3 b.9" read k if test "$k" = "b" then #echo "right ans" mark=`expr $mark + 10` echo "question 4 ans is : b.9 " >>temp else #echo "wrong ans" echo "question 4 ans is : a.3 " >>temp fi echo "====================================" echo -e "Question no 5 : \n=====================================" echo "Capital of USA" echo "a.Washington D.C b.Pheonix" read k if test "$k" = "a" then #echo "right ans" mark=`expr $mark + 10` echo "question 5 ans is : a.Washington D.C " >>temp else #echo "wrong ans" echo "question 5 ans is : b.Pheonix " >>temp fi echo "====================================" #echo "total mark $mark" echo "Total marks : $mark" >> temp l="==================================================" echo $l >> temp