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

MacosPerlBashCommand Line-InterfaceEnv

Macos Problem Overview


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

$ 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 script downloaded and unmodified from Daring Fireball.

I found this person with 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).

$ 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:

$ 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

Macos Solutions


Solution 1 - Macos

Did you happen to open/save the file in 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.

Solution 2 - Macos

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 forums for noticing that!).

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.

Solution 3 - Macos

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

More Info:Resolved Operation not permitted

Solution 4 - Macos

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

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

You can safely replace:

#!/usr/bin/env perl

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

#!/usr/bin/perl

Solution 5 - Macos

I ran into this after creating a shell script in BBEdit (CLI: bbedit ~/bin/foo). It seems that the macOS sandbox security feature automatically quarantines files modified by BBEdit — if the file is executable and is accessed by BBEdit in a certain way.

The fix is easy: Preferences > Application > Allow

https://www.barebones.com/support/bbedit/quarantine.html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNickView Question on Stackoverflow
Solution 1 - MacospilcrowView Answer on Stackoverflow
Solution 2 - MacosKPMView Answer on Stackoverflow
Solution 3 - MacosJaven.YangView Answer on Stackoverflow
Solution 4 - MacoslarsksView Answer on Stackoverflow
Solution 5 - MacosMat GesselView Answer on Stackoverflow