Bash script
Suppose you are working as a prof or TA and your students have an assignment which requires them each to hand in exactly one file. You've got a directory with all of the submitted files in it, and no other files. You're also lucky enough to have a script that will do all the work of marking a submission; it will take the name of a submission file as its only parameter and will print out a single upper-case letter (A, B, C, D or F) as its only output.
You'd like to know the distribution of marks in your class. Write a bash script called gradeDist.sh (the ".sh" extension is required!) that will take two parameters:
Your gradeDist.sh script must call the marking script to mark each file inside the folder and print a report showing the number of files earning each of the letter grades. If there are sub-folders inside the folder, your script must ignore them (and all of the files inside them). The only output of your gradeDist.sh script should be a list of how many submission files received each of the five possible marks.
File: gradeDist.sh
#!/bin/bash
# $1 will have the marking script
MARKING_SCRIPT=$1
# $2 will have the assignment submission folder
ASSIGNMENT_SUBMISSION_FILES_DIR=$2
# Declare variables for maintaining the counts of
# submissions of each grade
SUBMISSIONS_A=0
SUBMISSIONS_B=0
SUBMISSIONS_C=0
SUBMISSIONS_D=0
SUBMISSIONS_F=0
# loop through all the files in the supplied directory
for file in "$ASSIGNMENT_SUBMISSION_FILES_DIR"/*
do
# check if the current location being looped on
# is a file or not.
if [ ! -d "$file" ]; then
# Invoke the supllied grading script to grade the
# submission.
GRADE=`./$MARKING_SCRIPT $file`
# As per the grade of the submission increment
# the count of the respective grade counts.
if [[ $GRADE == 'A' ]];then
SUBMISSIONS_A=$(( SUBMISSIONS_A + 1 ))
elif [[ $GRADE == 'B' ]];then
SUBMISSIONS_B=$(( SUBMISSIONS_B + 1 ))
elif [[ $GRADE == 'C' ]];then
SUBMISSIONS_C=$(( SUBMISSIONS_C + 1 ))
elif [[ $GRADE == 'D' ]];then
SUBMISSIONS_D=$(( SUBMISSIONS_D + 1 ))
elif [[ $GRADE == 'F' ]];then
SUBMISSIONS_F=$((SUBMISSIONS_F+1))
fi
fi
done
echo "-----------------------------"
echo "GRADE | NUMBER OF SUBMISSIONS"
echo "-----------------------------"
echo "A | $SUBMISSIONS_A"
echo "B | $SUBMISSIONS_B"
echo "C | $SUBMISSIONS_C"
echo "D | $SUBMISSIONS_D"
echo "F | $SUBMISSIONS_F"
echo "-----------------------------"
How to run:
./gradeDist.sh {GRADING_SCRIPT} {ASSIGNMENT_DIR}
where GRADING_SCRIPT is the script that is used to grade the grade
the submissions
and ASSIGNMENT_DIR is the directory where the assigments are
there.
Example: ./gradeDist.sh test.sh folder
To test the
script
1. I wrote a grading file that would randomly grade the file
(test.sh):
#!/bin/bash
RANDOM_NUM=$RANDOM
RANDOM_NUM=$((RANDOM%5))
if [[ $RANDOM_NUM == 0 ]]; then
echo 'A'
elif [[ $RANDOM_NUM == 1 ]]; then
echo 'B'
elif [[ $RANDOM_NUM == 2 ]]; then
echo 'C'
elif [[ $RANDOM_NUM == 3 ]]; then
echo 'D'
elif [[ $RANDOM_NUM == 4 ]]; then
echo 'F'
fi
2. I created a folder named "folder" with random files
3. Then I ran ./gradeDist.sh test.sh folder
Output of the script :
akashpanda@DESKTOP-J1T11IR:/$ ./gradeDist.sh test.sh folder/
-----------------------------
GRADE | NUMBER OF SUBMISSIONS
-----------------------------
A | 2
B | 4
C | 2
D | 2
F | 4
-----------------------------
Get Answers For Free
Most questions answered within 1 hours.