bash Mac OS: /usr/bin/env: bad interpreter: Operation not allowed

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9952612/
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-09 21:53:27  来源:igfitidea点击:

Mac OS: /usr/bin/env: bad interpreter: Operation not permitted

macosperlbashcommand-line-interfaceenv

提问by Nick

I'm trying to run this script on Mac OS 10.7 (Lion) and I'm getting the error:

我正在尝试在 Mac OS 10.7 (Lion) 上运行此脚本,但出现错误:

$ bbcolors
-bash: /usr/local/bin/bbcolors: /usr/bin/env: bad interpreter: Operation not permitted

I've successfully run this script on other Macs of mine. It's just this scriptdownloaded and unmodified from Daring Fireball.

我已经在我的其他 Mac 上成功运行了这个脚本。这只是从 Daring Fireball 下载并未经修改的脚本

I found this personwith a very similar problem but the accepted answer was that the filesystem had a 'noexe' option on mount. I'm pretty sure that's not the case for me because I've just got it in /usr/local/bin/ and other stuff in there works fine (it also doesn't run from other places or as other users including root).

我发现这个人有一个非常相似的问题,但公认的答案是文件系统在挂载时有一个“noexe”选项。我很确定这对我来说不是这样,因为我刚刚把它放在 /usr/local/bin/ 和那里的其他东西工作正常(它也不能从其他地方运行或作为其他用户运行,包括 root) .

$ which bbcolors
/usr/local/bin/bbcolors
$ ls -l /usr/local/bin/bbcolors 
-rwxr-xr-x@ 1 nick  staff  9751 Mar 30 19:09 /usr/local/bin/bbcolors

It's a Perl script not a compiled binary, not that that should matter. Here's some extra info for what it's worth:

这是一个 Perl 脚本,而不是一个编译后的二进制文件,这不重要。以下是有关其价值的一些额外信息:

$ cat /usr/local/bin/bbcolors |head -n 1
#!/usr/bin/env perl
$ which perl
/usr/bin/perl
$ env | grep PATH
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

回答by pilcrow

Did you happen to open/save the file in TextEdit?

您是否碰巧在 TextEdit 中打开/保存文件?

That can introduce filesystem metadata (quarantine attribute) leading to the symptom you describe.

这可能会引入导致您描述的症状的文件系统元数据(隔离属性)。

Try:

尝试:

xattr -l /usr/local/bin/bbcolors

and

xattr -d com.apple.quarantine /usr/local/bin/bbcolors

if you see the quarantine attribute.

如果您看到隔离属性。

回答by KPM

pilcrow's answer is correct, however I draw your attention to the fact that if you are working with a disk image, the problem can be very confusing, as the com.apple.quarantine attribute seems to be inherited from the disk image file to the files inside (thanks to febeling at Apple dev forumsfor noticing that!).

pilcrow 的回答是正确的,但是我提请您注意这样一个事实,即如果您使用的是磁盘映像,则问题可能会非常令人困惑,因为 com.apple.quarantine 属性似乎是从磁盘映像文件继承到文件的内部(感谢Apple 开发论坛上的 febeling注意到这一点!)。

To solve the problem, you have to remove the quarantine attribute from the disk image:

要解决此问题,您必须从磁盘映像中删除隔离属性:

xattr -d com.apple.quarantine /path/to/disk/image

and then eject and remount the disk image. Then your files will be clean again.

然后弹出并重新安装磁盘映像。然后您的文件将再次干净。

回答by Javen.Yang

I had resolved this issue.Open the command file with TextEdit then save it.

我已经解决了这个问题。用 TextEdit 打开命令文件然后保存它。

More Info:Resolved Operation not permitted

更多信息:不允许解析操作

回答by larsks

-bash: /usr/local/bin/bbcolors: /usr/bin/env: bad interpreter: Operation not permitted

Does /usr/bin/envexist? Can you run it? Run by itself it should dump your environment variables to stdout.

是否/usr/bin/env存在?你能运行吗?自行运行它应该将您的环境变量转储到标准输出。

You can safely replace:

您可以安全地替换:

#!/usr/bin/env perl

With the full path to your perlbinary of choice, e.g:

使用您perl选择的二进制文件的完整路径,例如:

#!/usr/bin/perl