I’m having a problem with a simple loop… and I wonder what’s wrong with it.
Basically, I just want to increment a counter for each file found.
j=0
files=`ls path |grep "blabla"`
for i in $files ;
do j=`expr $j + 1` echo "$j ---- $i";
done;
RESULT:
0 ---- blabla1
0 ---- blabla2
0 ---- blabla3
0 ---- blabla3
Why is my counter not incrementing?
You’re missing a semicolon:
Without the semicolon, the variable assignment (
j=...) does not persist beyond theecho.