Remove DOS carriage return

After writing a shell script on Windows and trying to execute it on Linux, I got the following error message:

/bin/sh^M: bad interpreter: No such file or directory

The problem is obviously because the return line character on Windows and Linux are different. But how to fix it in order to execute it on Linux?
I firstly tried to open it, copy the content of the file and paste it in a new file using only Linux command line, but it didn’t work. 🙁

However, I found the following thread which fixed the problem:

Here is what you need to do:

  1. Open your file using vi
  2. Write the command :set fileformat=unix
  3. Save the file using :wq

The file should now run on Linux. 🙂

, , , , , , ,

  1. #1 by Ronny Roethof on 24 Oct 2012 - 14:37

    or use dos2unix.. probably easier.
    kvm01:~# sudo apt-get install dos2unix
    kvm01:~# dos2unix domains.txt
    dos2unix: converting file domains.txt to Unix format …

    thats it

(will not be published)