Question

In: Computer Science

Linux Shell Prpgramming 1.Write a quiz-script which will provide some statistics about a quiz results (summarize...

  1. Linux Shell Prpgramming
  2. 1.Write a quiz-script which will provide some statistics about a quiz results (summarize how many good answers and how many wrong answers were provided). The script should use up to 3 execution parameters. When executed with two parameters (let’s call it interactive mode), it should assume, that the first file contains a list of questions and the second file contains correct answers to these questions. In such execution case your script should display questions one by one and wait for users response. The user’s response should be then compared with the correct answer so that specific questions read from the file containing answers and as a result the script should produce statistics as to how many good and how many wrong answers were provided.

Questions should be formed so that either, YES or NO answer would apply. Questions file format can by any, whilst the answers format should contain only YES or NO answers, one answer per  line. There should be exactly 10 questionsin the quiz.

Assuming that file containing questions is qfileand the file containing answers isafile, to run your script in the interactive mode it should be executed as:

     ./scriptname qfile afile

How to test:

  1. Create a text file containing a number of questions.
  2. Create a text file containing correct answers to these questions.
  3. Execute your script:
    1. It should ask questions one at a time and then wait for your answer.
    2. Your answer should be then compared with the appropriate answer read from the file with answers,
    3. Depending on the correctness of your answer, the script it should count the answer and display statistics as:

Number_of_correct_answers     
Number_of_wrong_answers

Solutions

Expert Solution

Solution:

QAscript.sh

#!/bin/bash
question=$1
answer=$2
correctAnswer=0
wrongAnswer=0
while read -r -u 4 line1 && read -r -u 5 line2;
do
echo "$line1"
read -p "Ans(yes/no) :" ans
if [ "$ans" == "$line2" ];
then
#increment
correctAnswer=$((correctAnswer+1))
else
wrongAnswer=$((wrongAnswer+1))
fi
done 4<$question 5<$answer
echo "Number_of_correct_answers $correctAnswer"
echo "Number_of_wrong_answers $wrongAnswer"

qfile.txt

Is there 12 months in a year?
Is there 31 days in the month of january?
Is 2+2 is equal to 4?
Is 7*2 = 16?
Does total number of alphabets in english is 26?
Number of vowels in English is 5?
Number of consonants in English is 21?
Is dollar,the currency of USA ?
Is 3%2 is equal to 0?
Is 2/2 is equal to 2?

afile.txt

yes
yes
yes
no
yes
yes
yes
yes
no
no

OUTPUT :

To Run=>    ./QAscript.sh qfile.txt afile.txt


Related Solutions

Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string...
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string expressed as -rwxrwxrwx and prints out whether or not theobject is a directory, file or link. The string is read in from standard input. Convert String (Part 2) Modify the script so its able to print out the octal permission which the string represents along with the file type. This is in addition to part 1. Convert String (Part 3) For the script in...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt the user to "Enter a number between 1 and 10". (Hint: Use the 'echo' and 'read' commands in the script. See the slide about the 'read' command) If the number is less than 5, print "The number is less than 5" (Hint: You will read input into a variable; e.g. read NUM. In the IF statement, enclose $NUM in quotes; e.g. "$NUM". Also, remember...
Perl is a programming language that can be used on Linux. Write a Perl shell script...
Perl is a programming language that can be used on Linux. Write a Perl shell script named phone.pl that prompts the user to enter first or last or any portion of person’s name, so that can be found the appropriate entry in the phone directory file called “phones”. If the user tries to enter name as the argument on the command line, he/she will get a warning message “You need to provide name when prompted by this script!” If the...
Linux Sign into your lab account Write a bash shell script that does the following: Print...
Linux Sign into your lab account Write a bash shell script that does the following: Print out a friendly welcome message Ask the user for the name of their favorite animal Grep that animal from a text file noises.txt Tell the user what that animal says (i.e. what noise does it make) If the animal does not exist ask the user what noise the animal makes Store that new information in noises.txt
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within...
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within your script  Provide user feedback  Use loops  Use conditionals Remember to use chmod +x to make your file executable! Each script is 5 points in the Specifications portion of the rubric. Don’t forget to maintain good standards and comments. Script 1 – Echo-back some information Write a script name hello.sh that will take the user’s first name as a command line...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given only two integer numbers from command line arguments and computing their multiplication. If two integer numbers are not given, print “Wrong Input” on your screen. Note that, the number of arguments is known when the script runs. Take a screenshot showing your shell program and its execution step. Design a shell program to remove all the shell programming files ending with sh on your...
Revision Question 1 on Linux. Please briefly explain the shell script given. a) You have just...
Revision Question 1 on Linux. Please briefly explain the shell script given. a) You have just logged in and have a directory called "images" in your home directory containing the following files: favicons login.png logo.png newlogo.png where "favicons is a directory and contains the files favicon.ico favicon.gif favicon.png favicon.jpg Describe the results you would expect when executing the following shell commands: i) ls images/*og* | wc -1 ii) ls -ld images/* iii) rmdir images/favicons iv) cp images/*/*png images v) rm...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell script to take a directory as an argument and display the contents of that directory (10pts) Write a shell script that takes any command as a parameter and displays help on that command (e.g. the result of the execution of man <command>). (10pts) Write a shell script that requires two file names as parameters and copies content of one file into another without asking...
Write a complete shell script that first asks the user to enter a URL. The script...
Write a complete shell script that first asks the user to enter a URL. The script should read the URL into a variable named url. The shell script should then retrieve the file associated with the URL by using the curl command. The output of the curl command should be redirected to a file named html_file. The shell script should then use the grep command to search the file named html_file for the word manhattan. Finally, the shell script should...
write a “quiz” program on a topic, about which you are knowledgeable. this quiz can be...
write a “quiz” program on a topic, about which you are knowledgeable. this quiz can be work related, general knowledge or any set of questions where there is a specific answer. ignore questions where long descriptions or general answers needed. the program should display the questions, one at a time, and possible answers, and accept an answer from the user. if the answer is correct, the program should go on to the next question. if it is incorrect, store the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT