Qoute from the bash man page:
"Variables local to the function may be declared with the
local builtin command. Ordinarily, variables and their values are shared between the function and its caller."
I guess, the reason you need a function-local variable, is because you are recursively wandering through the directories. You may find it nicer to have the "find" utility handle the recursive directory search. Something like:
Code:
#!/bin/sh
find -type f | while read FILE ; do
mv "$FILE" "${FILE%/*}/`echo "${FILE##*/}" | tr A-Z a-z`" 2>/dev/null
done
Note that, by quoting properly, this does not need special handling of spaces. It's also not really needed to check if the file actually needs to be renamed: "mv" does that already, just directing the errors here it produces to /dev/null.