Script adding ^M to end of line

I trying to make a simple script to get info from remote servers my problem is the output of this line-

SERVER_NAME=`ssh -t $USER@$REMOTESERVER 'hostname'`

the output is

linux1^M

I would like to remove the ^M
where is my error?

Many Thanks

-Steve

99/100 it's because you have edited the script with a Microsoft Editor such as Notepad.

If so, to fix the script we need to remove the carriage-return characters:

cat old_script_name | tr -d '\r' > new_script_name
chmod 755 new_script_name