I count error lines like this: count=0; grep ERROR app.log | while read line; do count=$((count+1)); done; echo $count. Inside the loop the counter increases, but the final echo always prints 0.
Why is the variable reset after the loop, and what is the right way to read command output or a file line by line and keep the results?




