Well first off, this would appear to be a script and not working directly in the shell.
As for the error, which now makes more sense, you have created the file in windows and then run it in linux. Issue is that windows uses \r\n for line endings
and hence any variable being set now has \r at the end of it.
Try running dos2unix over the script first and see how you go.