To fix, open your script with vi or vim and enter in vi command mode (key Esc), then type this:
:set fileformat=unix
Finally save it
:x! or :wq!
:x!
:wq!
Looks like you have a dos line ending file. The clue is the ^M.
^M
You need to re-save the file using Unix line endings.
You might have a dos2unix command line utility that will also do this for you.
dos2unix
Or if you want to do this with a script:
sed -i 's/\r//' filename