0

I created a .txt file on Win 8 [using sublime] (with copied text for here) and moved it to my VM running Linux.

I used cat tmp.txt >> .bashrc to append those lines into .bashrc but mysterious ^M were added in the end of every line (I noticed after sourch .bashrc failed).

I removed those and now it's fine, but where did they come from?

Before and After image:enter image description here

1

1 Answer 1

1

Simple...

On Windows end-of-line is actually handled with 2 characters: ˆM (Carriage Return) and ˆJ (Line-Feed).
Unix-like systems, like Linux, only use ˆJ.
You save the file on Windows and Linux shows you the ˆM as a normal character.
I never used Sublime, but it probably has an option to convert between the 2 formats so you can just save the file in Unix format from Sublime.
(In fact: most text/programmers-editors have such options.)

3
  • 2
    it's not ^N. The newline in Windows is \r\n or 0D 0A which is ^M ^J because J is the 10th character in the alphabet
    – phuclv
    Jan 10, 2018 at 17:41
  • 1
    Google(unix2dos, dos2unix)
    – Hannu
    Jan 10, 2018 at 19:12
  • 1
    @LưuVĩnhPhúc Oh dear. Good you caught that. I've been doing too much C programming lately.
    – Tonny
    Jan 10, 2018 at 20:01

Not the answer you're looking for? Browse other questions tagged .