Skip to content

Commit 144ea16

Browse files
committed
bug fix: conflicting input stream in the while loop
1 parent 282828a commit 144ea16

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

run

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,19 @@ run() {
165165
elif [[ ${FILE#*.} == java ]]; then
166166
javac "$FILE"
167167
JCF=$(find . -type f -name "*.class" -mmin -1 | cut -c 3-)
168+
classFileCount=$(find . -type f -name "*.class" -mmin -1 | wc -l)
169+
168170
if [[ $COMPILE != true ]]; then
169-
while IFS= read -r classFile
171+
while [ "$classFileCount" -gt 0 ]
170172
do
171-
mainMethodCheck=$(grep -q "main" "$classFile" && echo "mainMethod")
172-
if [[ $mainMethodCheck == "mainMethod" ]]; then
173+
classFile=$(echo "$JCF" | awk "NR==$classFileCount{print}")
174+
mainMethodCheck=$(grep -q "main" "$classFile" && echo "mainMethodFound")
175+
if [[ $mainMethodCheck == "mainMethodFound" ]]; then
173176
java "${classFile%%.*}"
174177
break
175178
fi
176-
done < <(printf '%s\n' "$JCF")
179+
(( classFile-- ))
180+
done
177181
fi
178182
if [[ $PERSISTENT != true ]]; then
179183
find . -type f -name "*.class" -mmin -2 -exec rm -rf {} \; 2>/dev/null

0 commit comments

Comments
 (0)