I am trying to collect the data from a string of like "2.0 / 3.0".But when I try the following I get an error.
for i in t01 t02 t03 t04 t05 t06 t07 t08 t09 t10 t11; do
if [ -e "$i/feedback.txt" ]; then
grade=`tail -1 $i/feedback.txt | tr -d [:blank:]`
if [[ $grade =~ ^[0-9]+\.?[0-9]*/[0-9]+\.?[0-9]*$ ]]; then
IFS='/' read -ra grArray <<< "$grade"
score=${grArray[0]}
max=${grArray[1]}
total_tmax=$total_tmax+$max
total_t=$total_t+$score
echo $i: $score / $max
else
echo $i: 0 / 0
Output
t01: 4 / 4
t02: 2 / 3
t03: 3 / 3
t04: 3 / 3
t02/pp_marks.sh: line 39: 13+3.0: syntax error: invalid arithmetic operator (error token is ".0")