Background:
I posted a question on https://unix.stackexchange.com/questions/469680/teaching-assistant-bash-script-to-automate-the-process-of-finding-compiling-an and received some really good advice. Now I'd like to take my process one step further.
Summary of Design:
I'm a TA in University looking to automate testing my student's java code. I am also using this opportunity to grow in my bash skills because I feel like they could be better. My current bash script looks like this:
#!/bin/bash
list='/Users/ajm/Desktop/170Grading/output/list.txt'
score='/Users/ajm/Desktop/170Grading/output/score.txt'
> "$list"
> "$score"
find "$1" -name '*.java' >> "$list"
exec 3< "$list"
while IFS='' read -r -u 3 line || [ -n "$line" ]
do
read -p "> $line (Press Enter to continue)"
echo "the next file is $line" >> "$score"
open -a "Xcode" "$line"
javac -d "/Users/ajm/Desktop/170Grading/runs" "$line" >> class && echo compiled >> "$score" || echo not compiled >> "$score"
echo "standard in string" | cd "/Users/ajm/Desktop/170Grading/runs" java "$class" >> "$score"
done
Point of Contention
Currently, everything works up until the last line before the done. For some strange reason, the output from the java "$class" is not appended to "$score". Any guidance would be greatly appreciated.
Additional Goals
A) I would like to be able to take in additional parameters for my script so that I don't need to keep editing it for each new assignment. For example in:
find "$1" -name '*.java' >> "$list"
I would like to be able to replace the '*.java' with 'string.java'. I know that I can obtain the string as $2 as a command arg for the script, but '$2.java' does not seem to be the correct way of going about this. As an example: say I only want to look at a subset of .java files that end color.java, I would like to be able to say
bash script.sh directory color
and have that perform the task. If there is no $2, the code should default to '*.java'.