This is an assignment on Unix bash scripting. You have to modify and revamp a bash script. The original script shuffles the order of questions. The task is to modify the script so that it also shuffles the order of answers. See attachments below.
Bash scripting Step 1: Download the zip file containing the "ques_COP4342.bash" script and unzip the file: Step 2: If you run the current script, you can see that it shuffles the order of questions on each run: bash-4.2$ export QUIZDIR=./quizzes bash-4.2$ ./ques_COP4342.bash 1) CIS4385_quiz1 2) COP4342_quiz1 3) COP4342_quiz2 Choose a quiz: 1 The art of hiding and obscuring data (rather than encrypting it) is called: 1) Cryptography 3) Lithography 5) Riparian pursuits 2) Photography 4) Steganography #? 4 Correct. What is the Locard Exchange Principle? 1) Every contact between two entities leaves a trace on each of the entities. 2) Exchanges are allowed only on early evidentiary hearings but not later ones. 3) Evidence can be exchanged for testimony. #? 1 Correct. You answered 2 questions correctly, out of 2 total questions (100%). bash-4.2$ ./ques_COP4342.bash 1) CIS4385_quiz1 2) COP4342_quiz1 3) COP4342_quiz2 Choose a quiz: 1 What is the Locard Exchange Principle? 1) Every contact between two entities leaves a trace on each of the entities. 2) Exchanges are allowed only on early evidentiary hearings but not later ones. 3) Evidence can be exchanged for testimony. #? 1 Correct. The art of hiding and obscuring data (rather than encrypting it) is called: 1) Cryptography 3) Lithography 5) Riparian pursuits 2) Photography 4) Steganography #? 4 Correct. You answered 2 questions correctly, out of 2 total questions (100%). Step 3: Copy the original file ques_COP4342.bash to a new file, ques_ans_COP4342.bash. bash-4.2$ cp -i -v ques_COP4342.bash ques_ans_COP4342.bash ‘ques_COP4342.bash’ -> ‘ques_ans_COP4342.bash’ Step 4: Modify the ques_ans_COP4342.bash script so that it also shuffles the order of the answers. I came up with two different solutions; in each solution, I added one line and changed another. (In the first solution, I used "process substitution"; in the second, I used "command substitution".) When your newly modified script runs, the answers should now also be in a random order each time: bash-4.2$ ./ques_ans_COP4342.bash 1) CIS4385_quiz1 2) COP4342_quiz1 3) COP4342_quiz2 Choose a quiz: 1 The art of hiding and obscuring data (rather than encrypting it) is called: 1) Lithography 3) Photography 5) Cryptography 2) Riparian pursuits 4) Steganography #? 4 Correct. What is the Locard Exchange Principle? 1) Exchanges are allowed only on early evidentiary hearings but not later ones. 2) Evidence can be exchanged for testimony. 3) Every contact between two entities leaves a trace on each of the entities. #? 3 Correct. You answered 2 questions correctly, out of 2 total questions (100%). Step 5: Submit your modified ques_ans_COP4342.bash script __MACOSX/._DISTRO-2021-06-14 DISTRO-2021-06-14/.DS_Store __MACOSX/DISTRO-2021-06-14/._.DS_Store DISTRO-2021-06-14/ques_COP4342.bash #!/bin/bash # Adapted from exercise on pages 517-523 of Mark Sobell's "A Practical Guide to Linux", 4th edition # Uncomment the line below if you want debugging output # set -o xtrace # *********** I N I T I A L I Z A T I O N *********** function init() { trap 'summary ; exit 0' INT # Handle ctrl-c question_count=0 question_correct=0 cd ${QUIZDIR:=~/quizzes/} || exit 1 } # *********** --------------------------- *********** # *********** Q U I Z _ S E L E C T *********** function quiz_select() { subjects=$(ls) # It's probably not necessary to create a third shell, as the text does with ($(ls)) PS3="Choose a quiz: " select quiz in $subjects do if [[ -z "$quiz" ]] # No choice was made? then echo "No quiz was chosen." >&2 # Send this both stdout and stderr exit 2 else echo "$quiz" return fi done echo return } # *********** --------------------- *********** # *********** S H U F F L E *********** function shuffle() { order=$(ls . | shuf) } # *********** ------------- *********** # *********** A S K *********** function ask() { question=$(head -1 $1) correct_answer=$(head -2 $1 | tail -1) mapfile -t -s 2 possible_answers < $1="" #="" mapfile="" is="" a="" simpler="" way="" than="" using="" an="" explicit="" loop="" echo="" echo="" $question="" select="" ans="" in="" "${possible_answers[@]}"="" do="" if="" [[="" -z="" "$ans"="" ]]="" then="" echo="" not="" a="" valid="" choice.="" try="" again.="" elif="" [[="" "$ans"="$correct_answer" ]]="" then="" echo="" correct.="" return="" 1="" else="" echo="" no,="" the="" answer="" was="" "'$correct_answer'"="" return="" 0="" fi="" done="" }="" #="" ***********="" -----="" ***********="" #="" ***********="" s="" u="" m="" m="" a="" r="" y="" ***********="" function="" summary()="" {="" echo="" if="" ((="" question_count="=" 0="" ))="" then="" echo="" you="" did="" not="" answer="" any="" questions.="" exit="" 0="" fi="" ((="" percent="100" *="" question_correct="" question_count="" ))="" echo="" you="" answered="" $question_correct="" questions="" correctly,="" out="" of="" $question_count="" total="" questions="" '('${percent}%')'.="" }="" #="" ***********="" -------------="" ***********="" #="" #="" #="" #="" #="" main="" #="" #="" #="" #="" #="" init="" quiz="$(quiz_select)" [[="" $?="" -eq="" 0="" ]]="" ||="" exit="" 1="" test="" -z="" $quiz="" &&="" echo="" "no="" quiz="" selected"="" &&="" exit="" 1="" cd="" $quiz="" ||="" exit="" 1="" shuffle="" for="" question="" in="" $order="" do="" ask="" $question="" result="$?" ((question_count++))="" if="" [[="" $result="=" 1="" ]]="" then="" ((question_correct++))="" fi="" echo="" sleep="" ${quizdelay:="1}" done="" summary="" exit="" 0="" __macosx/distro-2021-06-14/._ques_cop4342.bash="" __macosx/distro-2021-06-14/._quizzes="" distro-2021-06-14/quizzes/.ds_store="" __macosx/distro-2021-06-14/quizzes/._.ds_store="" __macosx/distro-2021-06-14/quizzes/._cis4385_quiz1="" __macosx/distro-2021-06-14/quizzes/._cop4342_quiz1="" __macosx/distro-2021-06-14/quizzes/._cop4342_quiz2="" distro-2021-06-14/quizzes/cis4385_quiz1/q002="" the="" art="" of="" hiding="" and="" obscuring="" data="" (rather="" than="" encrypting="" it)="" is="" called:="" steganography="" cryptographical="" etymology="" photographic="" evidence="" lithography="" steganography="" riparian="" pursuits="" __macosx/distro-2021-06-14/quizzes/cis4385_quiz1/._q002="" distro-2021-06-14/quizzes/cis4385_quiz1/q001="" what="" is="" the="" locard="" exchange="" principle?="" every="" contact="" between="" two="" entities="" leaves="" a="" trace="" on="" each="" of="" the="" entities.="" every="" contact="" between="" two="" entities="" leaves="" a="" trace="" on="" each="" of="" the="" entities.="" exchanges="" are="" allowed="" only="" on="" early="" evidentiary="" hearings="" but="" not="" later="" ones.="" evidence="" can="" be="" exchanged="" for="" testimony.="" __macosx/distro-2021-06-14/quizzes/cis4385_quiz1/._q001="" distro-2021-06-14/quizzes/cop4342_quiz1/q002="" what="" directory="" embodies="" the="" "personality"="" of="" a="" unix/linux="" machine?="" etc="" embodies="" the="" "personality"="" var="" embodies="" the="" "personality"="" etc="" embodies="" the="" "personality"="" usr="" embodies="" the="" "personality"="" __macosx/distro-2021-06-14/quizzes/cop4342_quiz1/._q002="" distro-2021-06-14/quizzes/cop4342_quiz1/q001="" which="" of="" the="" following="" is="" a="" way="" to="" start="" a="" shell?="" run="" bin/bash="" run="" bin/bash="" run="" bin/true="" run="" bin/false="" run="" bin/ls="" __macosx/distro-2021-06-14/quizzes/cop4342_quiz1/._q001="" distro-2021-06-14/quizzes/cop4342_quiz2/q002="" how="" can="" use="" you="" use="" echo="" as="" a="" rough="" substitute="" for="" ls?="" echo="" *="" echo="" *="" echo="" $(ls)="" echo=""><><(ls) __macosx/distro-2021-06-14/quizzes/cop4342_quiz2/._q002 distro-2021-06-14/quizzes/cop4342_quiz2/q001 what is the difference between cd and pushd? when you use cd, it doesn't remember where you came from; with pushd, the original directory is saved on a stack. when you use cd, it doesn't remember where you came from; with pushd, the original directory is saved on a stack. the program cd is faster than the built-in pushd. the links of cd are faster than the links of pushd. __macosx/distro-2021-06-14/quizzes/cop4342_quiz2/._q001 __macosx/distro-2021-06-14/quizzes/cop4342_quiz2/._q002="" distro-2021-06-14/quizzes/cop4342_quiz2/q001="" what="" is="" the="" difference="" between="" cd="" and="" pushd?="" when="" you="" use="" cd,="" it="" doesn't="" remember="" where="" you="" came="" from;="" with="" pushd,="" the="" original="" directory="" is="" saved="" on="" a="" stack.="" when="" you="" use="" cd,="" it="" doesn't="" remember="" where="" you="" came="" from;="" with="" pushd,="" the="" original="" directory="" is="" saved="" on="" a="" stack.="" the="" program="" cd="" is="" faster="" than="" the="" built-in="" pushd.="" the="" links="" of="" cd="" are="" faster="" than="" the="" links="" of="" pushd.="">(ls) __macosx/distro-2021-06-14/quizzes/cop4342_quiz2/._q002 distro-2021-06-14/quizzes/cop4342_quiz2/q001 what is the difference between cd and pushd? when you use cd, it doesn't remember where you came from; with pushd, the original directory is saved on a stack. when you use cd, it doesn't remember where you came from; with pushd, the original directory is saved on a stack. the program cd is faster than the built-in pushd. the links of cd are faster than the links of pushd. __macosx/distro-2021-06-14/quizzes/cop4342_quiz2/._q001>