bash /bin/sh^M: 错误的解释器:没有那个文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23097528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 00:47:43  来源:igfitidea点击:

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

bashmacosterminalhomebrew

提问by that other guy

When I enter brew doctor(or any brewcommand) in my terminal, I get this as a response:

当我在终端中输入brew doctor(或任何brew命令)时,我得到以下响应:

-bash: /usr/local/bin/brew: /bin/sh^M: bad interpreter: No such file or directory

-bash: /usr/local/bin/brew: /bin/sh^M: 错误的解释器: 没有那个文件或目录

I have seen the ^Mresponse before and I think it has to do with dos line ending files. Is there a way to fix this?

我之前看到过^M响应,我认为它与 dos 行结束文件有关。有没有办法来解决这个问题?

回答by Javier Roca

This worked for me:

这对我有用:

  1. Open file /usr/local/bin/brew with vi (vi /usr/local/bin/brew)
  2. While on vi issue this commad (via esc or :) :set fileformat=unix
  3. Close file on vi via :wq!
  1. 用 vi ( vi /usr/local/bin/brew)打开文件 /usr/local/bin/brew
  2. 在 vi 上发出此命令时(通过 esc 或 :) :set fileformat=unix
  3. 通过 vi 关闭文件 :wq!

The brew command should be OK now.

brew 命令现在应该可以了。

Regards.

问候。

回答by that other guy

I don't know how carriage returns ended up in your brew file, but you can remove them using dos2unixor by piping it through tr -d '\r'.

我不知道回车如何在酿造文件结束了,但是你也可以使用删除dos2unix或通过管道它tr -d '\r'

Example:

例子:

tr -d '\r'  < /usr/local/bin/brew   > myfixedbrew

Once verified, you can use

验证后,您可以使用

mv myfixedbrew /usr/local/bin/brew && chmod a+x /usr/local/bin/brew 

to replace the old one.

更换旧的。