Script with ^M causes display issue with cat or more

I have a script to do a couple simple but repetitive commands on files that are provided to us. One of the things is to get rid of the line feeds. This is the section that is causing problems, i even cut this section into its own file to make sure nothing else was affecting it.

#!/usr/bin/bash
ls File_Name_* |while read FN
     do
          sed 's/^M//' ${FN} > ${FN}.tmp     ### the ^M is input with ^v^M
          mv ${FN}.tmp ${FN}
     done

It works fine and shows up fine in vi. but if i try to cat or more the file it shows

#!/usr/bin/bash
ls File_Name_* |while read FN
do
//' ${FN} > ${FN}.tmp/
                       mv ${FN}.tmp ${FN}
     done

Oh if i usr /usr/xpg4/bin/more it shows it all except the ^M itself:

#!/usr/bin/bash
ls File_Name_* |while read FN
     do
          sed 's///' ${FN} > ${FN}.tmp     ### the ^M is input with ^v^M
          mv ${FN}.tmp ${FN}
     done

Can someone explain this. The ^M is affecting the display of the file and i have never seen this before. This is on a Solaris 9 system.

1st query is working fine for me.
Would be great if you could show the output you are getting... I tried with vi, cat and more, I could see no ^M characters in the output files.
Or am I missing something?

^M stands for CarriageReturn (CR). Carriage return means go to the beginning of the line. So in the case of the cat, it writes:

          sed 's/

then it encounters the CR so it returns to the beginning of the line and prints:

//' ${FN} > ${FN}.tmp

meanwhile overwriting

          sed 's/

I did understand that the ^M is a carriage return, I didn't expect it to work from withing the '^M' quotes, especially single quotes.

What do quotes matter to cat, or the terminal itself? ^M is a terminal control character. If you print it, the cursor goes to the beginning of the line.

It may be an option for you to do something like

VAR=$'\r'

or

VAR="$(printf "\r")"

to avoid having to embed a literal carriage return in your script.