shell script returning counter value from a while loop - lost upon completion
Hi all
I need to know how to return a counter variable from a while loop.
Variable value is lost when exiting the while loop.
This is a stupid exacmple just to demonstrate the problem.
### ---------------------------- begin test.sh
typeset -x -i v=0
cat .bashrc | grep "^#alias" | while read line
do
v=`expr $v + 1`
echo "found $v $line"
done
echo "Total occurrences: $v"
### ---------------------------- end test.sh
When you run it, you'll get:
$ . test.sh
found 1 #alias ll='ls -l'
found 2 #alias la='ls -A'
found 3 #alias l='ls -CF'
Total occurrences: 0
Any help would be appreciated.
|