I have a while read loop that reads values inside of a file and then performs an expr operation on each.
Everything works fine, the way it's supposed to but, once the loop is finished, I can not access the variable that I used inside of the loop (but that variable was created outside of the loop).
In other words...
PHP Code:
#Init var
myVar=0
while read LINE
do
varInLoop=... #This carries an integer
myVar=`expr $myVAR + $varInLoop` #Trying to increment the totals
done
echo "myVar:${myVar}"
The output of that last echo is "myVar:0"
Is this something I'm not allowed to do? I changed the value of the variable I created outside of the loop, from within the loop, but it didn't change after the loop was done, outside.
I tested the loop, and yes, the loop works, the values are there.
Should I just redirect the output to a file and just use the file as my variable?