I am trying to count the number of files and lines of every .xls in directory where I executed the script.
total_files=0
total_lines=0
find . -type f -name "*.xls" | while read FILE; do
count=$(grep -c ^ < "$FILE") #get number of lines in particular file
total_lines=$(($total_lines+$count));
((total_files++))
done
echo "Total files: $total_files"
echo "Total lines: $total_lines"
But I just get 0 in totals every time.
I know that it is possibly because of while loop is executed in a sub shell,
but using <<<
to execute in the current shell wont help:
done <<< "$(find . -type f -name "*.xls")"