I hope noone runs your script from a dir named "
foo bar" (won't work) or
"| rm -rf *" (won't work and has nasty side effects). Why don't you use
readdir and
-d instead? It'll fix your bug, it'll be faster, it'll use less resources and it'll be portable.