Files edited in WINDOWS are often transferred to LINUX with a ^ M symbol at the end of each line, which leads to shell script running errors. This is because the DOS editor and the Linux editor are inconsistent with the carriage return character at the end of the file line. There are two ways to remove ^ M. 1. we can remove it in the VI editor...
Files edited in WINDOWS are often transferred to LINUX with a ^ M symbol at the end of each line, which leads to shell script running errors.
This is because the DOS editor and the Linux editor are inconsistent with the carriage return at the end of the file line.
There are two ways to remove ^ M
1. we can delete ^ M in the VI editor:
Switch VI to the command line mode, and enter (note that this ^ M is input, instead of shift + ^ plus M, it should be ctrl + v Plus ctrl + m)
: % S/^ M/g -- the command copy is invalid. Note that ^ M input
Run the preceding command in vi command line mode to remove the ^ M at the end of all lines.
2. you can use the dos2unix command.
Dos2unix filename
This article is from the "richard's note" blog