1. Use 'find' utility (that seems to be the answer for your question)
2. Imagine a file with name
some tricky $name$ with
newline characters
and think how your code would work like... In fact how it would NOT work
3. Try using high level shell (you have not specified whether this is a HTML document or shell code or whatever) like ksh,bash,zsh,etc. Then provide "magic number" in the first line.
4. If using a high level shell - use [[ ]] instead of [ ]
5. I tend to use ksh with $() in place of `` - think about `ls `cat pattern_file`` (you can do $(ls $(cat pattern_file)) )
6. If using ksh - try using print instead of echo
7. Avoid nested code (someone told me that writing a lot of if's is not a bad thing... but some other man told me to avoid if's whenever possible - the second one gave me a good advice while the first one wasted my time)
8. If you are using a high level shell then try using "${var}",'${var}' instead of what you wrote