I am using cgywin bash and i don't have this problem :
Code:
Var=0
echo "Before loop Pid:$$ Var:$Var"
while read oneline
do
((Var += 1))
echo " Inside loop Pid:$$ Var:$Var"
done < a.a
echo "After loop Pid:$$ Var:$Var"
the result is :
Quote:
Before loop Pid:429381 Var:0
Inside loop Pid:429381 Var:1
Inside loop Pid:429381 Var:2
Inside loop Pid:429381 Var:3
Inside loop Pid:429381 Var:4
Inside loop Pid:429381 Var:5
Inside loop Pid:429381 Var:6
After loop Pid:429381 Var:6
|
Some version of shell creates a subprocess to execute the statements into the loop, in that case the modifications of the environment are lost when exiting the loop.
Try my script and verify that the Pid is the pid is the same outside and inside the loop.
You can also try to export your variable.