从github clone了一个项目,在执行其中的shell脚本时,遇到了如下报错:
/bin/bash^M: bad interpreter: No such file or directory
经查阅资料,发现是文件编码的问题。在windows上编辑的文件,格式为dos,在linux中执行,需要转换格式为unix。
-
查看文件编码fileformat
在vim中打开shell脚本,执行 :set ff? -
更改文件编码
执行 :set ff=unix
也可以通过其他文本编辑器转换格式。
参考:
https://www.cnblogs.com/pipelone/archive/2009/04/17/1437879.html
https://stackoverflow.com/questions/14219092/bash-script-and-bin-bashm-bad-interpreter-no-such-file-or-directory

本文介绍了在Linux环境下执行从GitHub克隆的项目中的Shell脚本时遇到的/bin/bash^M:badinterpreter:Nosuchfileordirectory错误。错误原因是文件编码格式不匹配,文章提供了使用vim编辑器更改文件编码格式的方法,即将格式从DOS转换为UNIX,以确保脚本能够正常运行。
1789

被折叠的 条评论
为什么被折叠?



