How to deal with the file opened under Linux with ^M

How to deal with the file opened under Linux with ^M

principle

'\r' under DOS system will be displayed as ^M under Unix-like system.
A newline is an end-of-line (EOL), a special character or sequence of characters that signifies the end of a line of text and the beginning of a new line; the
actual code that represents a newline varies by operating system: -- Microsoft Windows, DOS (MS- DOS, PC DOS, etc.) use CR + LF; -- Unix and Unix-like systems use LF, including Linux, OS X, FreeBSD, etc. use LF; -- MAC systems use CR; CR is the ASCII code 0x0D (\r
) , LF is 0x0A (\n) of ASCII code, used in DOS (\r\n), used in Unix-like system (\n), and '\r' in DOS system will be displayed as ^ in Unix-like system M
intuitively affects
that if the file under the Unix/Mac system is opened in Windows, all the text will become one line (due to the processing of the editor under Windows, this situation generally does not happen); while the
file in Windows is under Unix/Mac If it is turned on, there may be an extra ^M symbol at the end of each line;

Influence

Scripts such as shell and python written on Windows cannot be executed normally on Linux, and there will be a ^M related prompt; if the
file under the Unix/Mac system is opened in Windows, all text will become one line (due to Windows The processing of the editor, this situation generally does not happen);
and if the file in Windows is opened under Unix/Mac, there may be an extra ^M symbol at the end of each line;

Solution

Just re-modify the corresponding line break format in the editor.
Take Pycharm as an example, directly modify the Line Separator in the lower left corner to LF; (choose according to your own operating system)
insert image description here
Reference: https://new.qq.com/rain/ a/20220624A0455800

Guess you like

Origin blog.csdn.net/qq_40804558/article/details/127491180