Here is a copy of my current code:

echo "" > list
echo "" > score
find $1 -name '*.java'>> list
exec 3<list
while IFS='' read -r -u 3 line || [[ -n "$line" ]];
    # 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")  && (echo compiled >> score)) || ((echo not compiled) >> score) 
    echo "" | cd "/Users/ajm/Desktop/170Grading/runs" java "$line" >> score

When the students have submitted their files for grading, I downloaded a .zip file from the course website. I unzipped this file to a parent folder on my desktop called 170Grading.

In this 170Grading parent folder, there are two additional sub-folders, these subfolders are called output and runs.

My first goal is to extract the path of every class file in this parent directory 170Grading and add it to a file. Then I would like to compile each .java file to a .class file. Finally I would like to run these .class files with a standard input, and record the output in a text file.

I would like to run each file one at a time so that I can examine the students' code submission, and note any odd choices or places where there is room for improvement.

Currently, the script can, correctly, find all .java files and place them in the file list.txt. The lines:

# read -p "> $line (Press Enter to continue)"
echo "the next file is $line" >> score 
# open -a "Xcode" "$line"  

also work correctly. Unfortunately the last two lines of my code are failing to do what I want, and probably need to be revised. The code does not compile correctly, and therefore the last line fails to output anything as well. I recognize that I can't use "$line" in the second to the last lines of my code, because when the code was compiled the path /path/to/this/example.java becomes example.class.

closed as too broad by RalfFriedl, G-Man, Rui F Ribeiro, maulinglawns, Archemar Sep 18 '18 at 7:30

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • running random student code might be better done in a virtual machine rather than the desktop of what looks like your own account... – thrig Sep 18 '18 at 1:05

There are too many errors in the script for me to review.

I could even create space for more errors, unfortunately.

Let's have a look at a more plausible code, maybe it'll help you fix it:



echo "" > "$list"
echo "" > "$score"

find "$1" -name '*.java' >> "$list"

exec 3< "$list"

while IFS='' read -r -u 3 line || [ -n "$line" ]

    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" && echo compiled >> "$score" || echo not compiled >> "$score"

    echo cd "/Users/ajm/Desktop/170Grading/runs" java "$line" >> "$score"

  • Thanks for the more plausible code. I'll be sure to be more careful to use flags on variables that I create in the script. Should I ask a new question to help me figure out, why the last line before the done fails? – Allan J Miller Sep 18 '18 at 2:50
  • @AllanJMiller You can, of course, ask a new question, but better on stackoverflow.com where these programmers mostly are. Here we do general Linux stuff mostly. – LinuxSecurityFreak Sep 18 '18 at 2:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.