[Linux] Shell script execution error $'\r': command not found

Insert picture description here

1 Overview

When the script is executed on Linux, $'\r':command not found appears. However, if you check the script carefully, the corresponding line is just a blank line, which is no problem. Then why does Linux report a blank line with a carriage return error?

The reason is this: the script is uploaded to Linux for execution after editing under the window, the +line feed under win is the carriage return line feed, that is \r\n, the line feed under Unix \n. Under linux, \r is not recognized as a carriage return, so there are more configurations for each line \r, so it is a foot 本编码的问题.

2. Solution 1

yum install dos2unix
dos2unix 脚本名

Execute on linux dos2unix 脚本名, execute the script again, the error message disappears.

3. Solution 2

sed -i 's/\r//' 脚本名

Guess you like

Origin blog.csdn.net/qq_21383435/article/details/109305582