“bad interpreter: Operation not permitted” Error on El Capitan
Asked Answered
B

3

13

My team is writing a Mac OS application that needs to call a shell script in an external directory.

The application works fine on Yosemite (10.10.3). However, if I run it on El Capitan (10.11.2), the application gets errors like this from the script:

/bin/bash: <path-to-script>: /bin/sh: bad interpreter: Operation not permitted

I can trigger this error on a simple script like this:

#!/bin/sh
echo "Hello World!"

I do not get an error if I run the scripts manually from the Terminal.

The application opens the script directory using a filechooser. I confirmed that the application can read other files from this directory.

Changing /bin/sh to /bin/bash or a copy of /bin/sh on a different path gives the same error with the new interpreter path.

A coworker tested this issue on a El Capitan machine with System Integrity Protection disabled, but he got the same error.

I am installing the test application from a .pkg file. The entitlements are:

<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/>

Adding the com.apple.security.files.user-selected.executable entitlement did not make a difference

If I try to run the .app that is generated in an intermediate step in the package build, I am able to run the script with no errors.

The question below describes a similar error. However, I checked both the application and the script, and I found that neither one had the com.apple.quarantine attribute set.

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

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

--- UPDATE ----

We added two more in PKG entitlement list:

<key>com.apple.security.scripting-targets</key>
<true/>
<key>com.apple.security.temporary-exception.apple-events</key>
<true/>

We tried to run the simple .sh file by an AppleScript (.scpt) file (stored in application directory), we also confirmed that the .sh file nor the .scpt file has any extended attribute as well, but we still have that error.

Following shows ls -@Oel commands on both AppleScript and shell script file respectively.

$ 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
Budding answered 10/6, 2016 at 5:18 Comment(6)
might it be a thing of the line-ending-style, maybe the script uses dos-stype CR-LF or unix-style only LF instead of only-CR? just an ideaContinuate
What happens if you explicitly run /bin/sh /path/to/script does it run with that?Underhill
What do you get with ls -l /bin/sh ?Protectionist
@Underhill As mentioned the command is running good when run on Terminal manually but not inside application.Budding
@Cdarke If I ran the command on Terminal manually I had this: -r-xr-xr-x 1 root wheel 632672 Dec 3 2015 /bin/sh. I'll plan to run this from our application if you think otherwise.Budding
& what line endings does it show for file /path/to/script ?Underhill
B
26

try this: $ ls -l@ whereverthescriptis If it says it's got com.apple.quarantine, that's the problem. Run one of these on it, from least dangerous to most:

$ 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
Befall answered 1/6, 2019 at 0:42 Comment(2)
Just ran into this in 2020 on macOS Catalina.Ayana
Worked in 2021 macOS Monterey, thanks.Summarize
N
3

I hope this will help someone, because mine was a slightly unique solution of the above problem: I had someone else do the code for me, so when I got the code, it would not run with "Operation Not Permitted" status on both android and iOS.

It turns out that I have to go to the folder that contained the project, and take ownership of the folder. You can do this on a Mac by going to the folder containing the Flutter project, and clicking on "Get info" from the context menu. Then change your access rights to "read-only", then back to "write and read" in the last pane in the bottom.

Follow this by one of the advices above to remove the Apple quarantine attribute from the folder by going to Terminal, then use "cd" command to navigate to the folder containing your Flutter project, and typing the following command:

xattr -dr com.apple.quarantine [your flutter project directory name]

That's it! Now Android Studio, or your IDE of choice, will be able to run both iOS and Android versions from that folder.

Norther answered 24/5, 2021 at 23:18 Comment(1)
I am really happy it did. Good luck.Norther
M
2

i am solve it if you using pods just

  1. pod deintegrate
  2. pod install

and project ready to run

Meetly answered 30/1, 2020 at 21:49 Comment(2)
Could you explain what pod actually is and how I would install it? Just to prevent some misunderstandingsBerkie
I dont know why it happened, but this solution worked without any problem.Suppressive

© 2022 - 2024 — McMap. All rights reserved.