Since the main problem has been diagnosed, I'd like to post a few comments about the script itself in the OP.
1) First of all, please use
[code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.
2) Clean, consistent formatting makes code readable and more easily debuggable. Indent all your sub-commands, and separate logical sections with whitespace. Add comments anywhere the code isn't completely obvious (and remember, what seems obvious to you now will not be a year or so down the line).
Many people also think that it makes it more readable to place the "
do/then" keywords on the same line as the "
for/while/until/if" keywords. It more clearly separates the outside block from the inside block.
Code:
for var in <list> ; do
<commands>
done
3) #!/bin/sh is used for interpreting scripts in posix-compliant lowest-common-denominator mode. This is mostly recommended for system startup scripts and other cases where portability and standardization are more important than convenience. When this isn't required, you should probably use #!/bin/bash or another shell that has more modern, advanced features available, such as ksh or zsh.
4)
$(..) is highly recommended over `..`
5) Environment variables are generally all upper-case. So while not absolutely necessary, it's good practice to keep your own user variables in lower-case or mixed-case, to help differentiate them.