Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/bin/bash^M: bad interpreter: No such file or directory 问题解决方案 #12

Open
yangruihan opened this issue Sep 27, 2020 · 0 comments

Comments

@yangruihan
Copy link
Owner

/bin/bash^M: bad interpreter: No such file or directory 问题解决方案

问题描述

执行xxx.sh时,提示/bin/bash^M: bad interpreter: No such file or directory,打开文件显示正常

问题原因

出现上面错误的原因之一是脚本文件是DOS格式的,即每一行的行尾以\r\n来标识,我这里是因为在 macOS 上运行 Windows 下git clone的代码库里的脚本

解决方案

使用dos2unix命令

macOS上安装brew install dos2unix

然后对对应文件执行dos2unix xxx.sh即可

  • 递归将某个目录下所有文件转换:find . -type f -print0 | xargs -0 dos2unix

  • 递归将某个目录下所有以.sh结尾的文件转换:find . -name "*.sh" -print0 | xargs -0 dos2unix

参考资料

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant