So here's my script :
count=0
cat myfile | while read line
do
#some stuff...
let count++
echo $count
done
echo $count
The last echo statement output 0 instead of the number of lines in the file, although the echo statement in the while loop prints the incrementing value.
The problem is with the piping, because, with a simple while loop, the last echo statement prints the correct value. How can I get this to work?