So here is my script:
count=0
cat myfile | while read line
do
let count++
echo $count
done
echo $count
The final output of echo prints 0 instead of the number of lines in the file, although the echo statement in the while loop prints an extra value.
The problem is with the pipeline, because with a simple while loop, the last echo statement prints the correct value. How can I make this work?
source
share