Execute function for every subfolder

I have a folder named students_projects that contains 10 subfolders. Each subfolder has project1.c and project2.c, each one prints a value. I made a bash script function that check those numbers and save them to a txt file. I tested it with 2 .c files named project1 and project2 in Desktop and not in the folder. I made sure that i worked fine but when i went to run it for all the subfolders it keeps saving the values that are in desktop files.

My function:

function test () {
  gcc project1.c
  p1=$(./a.out)
  if (( $p1 == 20 ));
  then
    v1=30
  else
    v1=0
  fi
  gcc project2.c
  p2=$(./a.out)
  if (($p2 == 10 ));
  then
    v2=70
  else
    v2=0
  fi
  sum=$(( $v1 + $v2 ))
  on="cut -d' ' -f1 report.txt"
  onoma=$(eval "$on")
  temp="cut -d' ' -f2 report.txt"
  am=$(eval "$temp")
  printf "$onoma $am project1: $v1 project2: $v2 total_grade: $sum\n" >> grades.txt
}

Then i do

for FILE in students_projects/* ; do
  test
done


from Recent Questions - Stack Overflow https://ift.tt/3FAXXLf
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation