Homework 9
Shell Scripting
This assignment involves Bash shell scripting to write a simple autograder.sh
that evaluates (made-up) student submissions to a homework assignment. Given a set of students’ submission directories, each of which should contain a file task1.sh
(though not all students will submit the correct files), your script will attempt to run each one and compare the output against the expected output to determine a score for each student. Here is one example output corresponding to ./autograder.sh 50
for the students joshue
, dravir
, joeblow
, and oterod
:
Autograding CSE 391 Homework
Grading with a max score of 50
Processing joshue ...
joshue has correct output
joshue has earned a score of 50 / 50
Processing dravir ...
dravir has incorrect output (1 lines do not match)
dravir has earned a score of 45 / 50
Processing joeblow ...
joeblow has incorrect output (4 lines do not match)
joeblow has earned a score of 30 / 50
Processing oterod ...
oterod did not turn in the assignment
oterod has earned a score of 0 / 50
Download the homework files on attu
After logging into attu
, download the homework files.
git archive --remote=git@gitlab.cs.washington.edu:cse391/25wi/hw9.git --prefix=hw9/ HEAD | tar -x
In the hw9
directory, you will find:
expected.txt
- A file containing the expected output for
task1.sh
for comparison against each student submission. students
- A directory containing subdirectories for each student containing their submission files, such as:
students/joshue/task1.sh students/dravir/task1.sh students/joeblow/task1.sh students/oterod/TAsk1.sh
Each student’s directory is supposed to contain a file representing that student submission, but some students may have typos or other submission problems and will not receive credit for the assignment.
Since the goal is to write a generalizable autograder, we won’t be able to hard-code the names of each student. But you can assume that each student subdirectory name consists of only alphabet characters (no whitespace or special characters), and that student submissions will not get stuck in an infinite loop.
Step 1: Handle arguments
Let’s begin writing the autograder.sh
script by handling the maximum score command-line argument. If the user does not pass a value for the maximum points, your script should instead print exactly the following error message and exit with a non-zero exit code:
Usage: ./autograder.sh MAXPOINTS
You do not need to check this argument for validity: if an argument is passed, assume it is a positive integer. Given the max score argument, the script should print a welcome message displaying the max score, such as 50
:
Autograding CSE 391 Homework
Grading with a max score of 50
Step 2: Count differences for each student
Now that we have the max score, the autograder will now begin processing student submissions assuming the current directory contains expected.txt
and a students
directory. For each student subdirectory:
- Manually invoke
bash
to run the student’stask1.sh
file (if it exists) from the student’s subdirectory as the working directory. - Capture the file’s output and compare it against the expected output file using
diff
ignoring whitespace (read theman
pages to learn how). - Using the
diff
output (ignoring whitespace), count the number of lines containing<
or>
as 1 line of mismatched content, deducting 5 points for each mismatch down to a min score of 0 points.
Step 3: Print student progress summaries
Finally, for each student, print four lines of output to summarize the student’s progress.
- Print
Processing joshue ...
for the studentjoshue
. - Print a correctness summary, which depends on the student’s submission:
- If the student
joshue
has a fully correct submission, printjoshue has correct output
. - If the student
smith
has an incorrect submission (at least one difference), printsmith has incorrect output (8 lines do not match)
with the corresponding line count. - If the student
lewis
did not turn in a program namedtask1.sh
, printlewis did not turn in the assignment
.
- If the student
- Print the score deducted from the max score according to the number of diff lines like
joshue has earned a score of 35 / 50
for the studentjoshue
.
It is okay if your autograder.sh
script creates temporary files while doing its work: just make sure to remove them as you go along.