Why does my Bash counter reset after while loop

In the just-released Bash 4.2, you can do this to prevent creating a subshell:

shopt -s lastpipe

Also, as you’ll probably see at the link Ignacio provided, you have a Useless Use of cat.

while read -r line
do
    ...
done < afile

Leave a Comment