I am having some difficulty understand why i'm not able to enter my while read j loop. The goal of my program is to enter files 1-5 and calculate the sum of the numbers in each file. The output i'm getting is showing me that the read j line is executed, however the while loop isn't entered. This doesn't make intuitive sense to me, since the while condition would be true if the line is read. Heres the output, and the snippet of program below:
in for loop
file1
in for loop
1 9 6 3 3 6
file2
in for loop
1 3 7 6 4 4
file3
in for loop
1 4 8 8 2 4
file4
in for loop
1 5 9 9 1 7
file5
Code:
for (( n=0;n<$columns;n++ ))
do
echo "in for loop"
echo $j
filename="file$counter"
echo "$filename"
#while reading line from current file, take the numbers and find the sum
while read j
do
echo "in while loop"
for number in $j
do
sum=$(($sum + $number))
done
echo "Sum: $sum"
done < $filename
counter=$(($counter + 1))
done