bash: ./configure: /bin/sh^M: bad interpreter: No such file or directory

问题背景:

在linux上编译Qt时,遇到这个问题

“bash: ./configure: /bin/sh^M: bad interpreter: No such file or directory”

问题原因:

Qt的configure文件是在windows上写的,现在是在ubuntu上进行编译。而linux和windows在换行符上存在差别。在windows下编写代码时,每行后面会加个ctrl+m,就是^M。所以,当在ubuntu中运行configure脚本时,当运行到里面的sh命令行,把“sh”就识别成了“sh^M”,导致无法执行sh命令,所以脚本就不能运行了。

解决方式:

把configure文件中的“^M”去掉就可以了。

方法1:

        安装:dos2unix

sudo add-apt-repository universe
apt-get install dos2unix

        输入命令:

dos2unix configure 

        把configure文件转化成linux编码格式。

方法2:

        在没有dos2unix情况下

cat ./configure.sh | tr -d ‘/r’ > temp.sh
mv temp.sh configure.sh

你可能感兴趣的:(bash,开发语言)