Today, using notepad++ to write a Python script under Windows, to the Linux server after the execution prompt:-bash:./logger.py:usr/bin/python^m:bad interpreter:no Such File or directory
1. Cause Analysis
this is caused by different system encoding formats: The logger.py file edited in the Windows system may have invisible characters, so the above exception information is reported in the Linux system execution. This is generally due to the fact that the end of the Windows line and the end of the Linux line are different, the end of the row in the window is the ' \ r \ n ' table, and the end character in Linux is ' \ n ', and ^m is the ' \ R ' in ASCII.
2. Workaround
1) Convert under Windows:
use some editors, such as UltraEdit or EditPlus, to first convert the script encoding and then put it into Linux for execution. The conversion mode is as follows (UltraEdit): File-->conversions-->dos->unix.
2) Direct replacement under Linux:
sed-i ' s/^m//g ' filename, meaning to replace the ^m in each row of the filename is/(note ^m in Linux, press ^m is the carriage return newline character, the input method is to press CTRL + V, Loosen v., press M)
3) can also be converted in Linux:
first, make sure the file has executable permissions: chmod a+x filename, and then modify the file format: Enter VI filename, then use the set FF (or set FileFormat) command to view the file format for Fileformat=dos or Fileformat=unix,then use the following command to modify the file format: Set Ff=unix or: Et Fileformat=unix; final Wq (save exit)
Finally, execute the file again./filename