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...
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...
(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 shell script (to run on the Bourne shell) called cp2.sh to copy all the...
Write a shell script (to run on the Bourne shell) called cp2.sh to copy all the files from two named directories into a new third directory. Timestamps must be preserved while copying files from one directory into another. Task Requirements Three directory names must be supplied as arguments to your script when it is executed by the user. In the beginning of your script you need to check that the first two directory names provided (e.g. dir1 and dir2) exist...
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...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all the files in a directory. b. Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line of a file? c. Write a bash command or script to find all the files modified in less than 5 days and print the record count of each.
Write a brief shell script that will take in a specific file name, prompt the user...
Write a brief shell script that will take in a specific file name, prompt the user whether they would like to gzip, bzip2, or xz compress the file. Depending on response, the script then ought to compress the provided file with the corresponding method
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT