php-config: /bin/sh^M: bad interpreter: no such file or directory

Because some projects need to install some PHP extensions, prompt when executing ./configure

php-config: /bin/sh^M: 坏的解释器: 没有那个文件或目录

At first, I thought that this file had been modified. Finally, I compared it with the php-config on the test server and found that the content was the same, but the result returned by executing php-config was different. Finally, I executed the cat command to check and found out where the problem was.

cat -A php-config

The following is a screenshot of the content of the file in question. Note that there is an extra (^M) at the end of each line.

It turns out that this is related to wdcp. After the file is opened and edited through the file manager of wdcp, there will be an extra character \r at the end of each line, which becomes \n\r, and the end of the file under linux is \n, then When you open it under linux, there will be an extra character \r at the end of each line. When you use cat -A to view the content, \r will be displayed as ^M

Solution

The following is the execution command (replace the characters ending with \r with blanks)

sed -i 's/\r$//' php-config

Parameter Description

-i   插入
s     替代模式
\r$   表示任何以\r结束的字符

Special Note

The end of the edited file under Windows is also \n\r, so it needs to be replaced after uploading to the Linux server. Therefore, it is not recommended to edit the system file under Windows and the wdcp file manager to avoid exceptions caused by some reasons. It's not good to cause a loss

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325000112&siteId=291194637