“错误的解释器:不允许操作” El Capitan 上的错误

San*_*rar 7 bash file-permissions mac-app-store pkg-file osx-elcapitan

我的团队正在编写一个需要在外部目录中调用 shell 脚本的 Mac OS 应用程序。

该应用程序在优胜美地 (10.10.3) 上运行良好。但是,如果我在 El Capitan (10.11.2) 上运行它,应用程序会从脚本中收到如下错误:

/bin/bash: <path-to-script>: /bin/sh: bad interpreter: Operation not permitted
Run Code Online (Sandbox Code Playgroud)

我可以在这样的简单脚本上触发此错误:

#!/bin/sh
echo "Hello World!"
Run Code Online (Sandbox Code Playgroud)

如果我从终端手动运行脚本,我不会收到错误消息。

应用程序使用文件选择器打开脚本目录。我确认应用程序可以从此目录读取其他文件。

更改/bin/sh/bin/bash/bin/sh在不同路径上的副本使用新的解释器路径会产生相同的错误。

一位同事在禁用系统完整性保护的 El Capitan 机器上测试了这个问题,但他得到了同样的错误。

我正在从 .pkg 文件安装测试应用程序。权利是:

<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.files.bookmarks.app-scope</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
Run Code Online (Sandbox Code Playgroud)

添加com.apple.security.files.user-selected.executable权利没有任何区别

如果我尝试运行在包构建的中间步骤中生成的 .app,我可以运行脚本而不会出错。

下面的问题描述了一个类似的错误。但是,我检查了应用程序和脚本,发现都没有com.apple.quarantine设置属性。

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

https://apple.stackexchange.com/questions/49589/bash-applications-mvim-bin-sh-bad-interpreter-operation-not-permitted

- - 更新 - -

我们在 PKG 权利列表中又添加了两个:

<key>com.apple.security.scripting-targets</key>
<true/>
<key>com.apple.security.temporary-exception.apple-events</key>
<true/>
Run Code Online (Sandbox Code Playgroud)

我们尝试通过 AppleScript (.scpt) 文件(存储在应用程序目录中)运行简单的 .sh 文件,我们还确认 .sh 文件和 .scpt 文件也有任何扩展属性,但我们仍然有那个错误.

下面分别显示ls -@Oel了 AppleScript 和 shell 脚本文件上的命令。

$ ls -@Oel TestMXMLCall.scpt 
-rwxrwxrwx  1 root  wheel  - 2302 Jun 15 03:12 TestMXMLCall.scpt
$ ls -@Oel /usr/local/bin/mxmlc
-rwxr-xr-x  1 santanukarar  staff  - 2190 Jun 15 01:17 /usr/local/bin/mxmlc
Run Code Online (Sandbox Code Playgroud)

Osa*_*gin 18

试试这个: $ ls -l@ whereverthescriptis 如果它说它有com.apple.quarantine,那就是问题所在。运行其中之一,从最不危险到最危险:

$ xattr -d com.apple.quarantine whereverthescriptis   # delete that attr
$ xattr -c whereverthescriptis    # delete ALL the attrs on file
$ xattr -c *         # on every file in this dir
$ xattr -cr .        # and all subdirectories
Run Code Online (Sandbox Code Playgroud)

  • 2020 年刚刚在 macOS Catalina 上遇到了这个问题。 (2认同)