On DOS/Windows, the end of a line consists of a carriage return character followed by a line feed character (). On Unix, the end of a line is marked by just a line feed character (). On Mac OS, the end of a line is marked by a carriage return ().
Some programs, such as the Python interpreter, have problems when you try to use a file that was formatted for the wrong platform. You can tell you have a DOS formatted file on Unix if you open the file in a text editor on the Unix system and some or all of the lines end with a ^M character.
One way to fix the problem on each file is to use the dos2unix program on the Unix box. You will need to get a shell connection, such as via telnet or ssh.
After you cd into the directory with the file, just enter:
If you want to see what other options dos2unix offers, enter:
You can use standard shell wildcards to apply it to multiple files in a directory. The following command will convert all the .py files in the current directory:
Another option is to use a Windows or Mac text editor that has an option for saving files with Unix line endings. This is a good option if you aren’t comfortable using the Unix shell.