I am having some issues with local variables after exiting a loop. The variable max
ends up with the value 0, despite the code below:
max=0
cat
The pipe before your while is putting everything inside the loop into a separate shell, and thus a separate identifier context (essentially a new environment).
Redirecting the tmp
file into the while
loop via <
will keep your loop and variables all in the same execution context.
while read line
do
# your loop stuff
done < tmp