I'm trying to do a simple bash script to do something in one of each file in a set of folders. Also I like to count how many files the script read, but when the script pass of the loop, the numerical variable is reseted.
The code I'm using is like that
#!/bin/bash
let AUX=0
find . -type "f" -name "*.mp3" | while read FILE; do
### DO SOMETHING with $FILE###
let AUX=AUX+1
echo $AUX
done
echo $AUX
I can see that AUX is counting inside the loop, but the last "echo" prints a 0, and the variable seems to be really reseted. My console output is like that
...
$ 865
$ 866
$ 867
$ 868
$ 0
I would like to preserve in AUX the number of files proccesed. Any idea?