59

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
Community
  • 1
  • 1
Nick
  • 3,172
  • 3
  • 37
  • 49
  • 1
    You've covered most of the normal bases for what might be going wrong; well done. What happens when you run `perl -v`? What appears after the initial comment lines in the Perl script (`bbcolors`)? Also, the `@` after the permissions means there is some auxilliary attribute information for the file; have you investigated that that is (perhaps with `ls -@`)? – Jonathan Leffler Mar 31 '12 at 02:58
  • I solved the problem with `xattr -r com.apple.quarantine /file/path` I will answer my own question but I don't have enough rep to do it for a few hours. – Nick Mar 31 '12 at 03:19
  • `xattr -d com.apple.quarantine /usr/local/bin/bbcolors`? (`-r` means 'recursive'; `-d` means 'delete'.) I keep forgetting what that command is called. – Jonathan Leffler Mar 31 '12 at 03:23

6 Answers6

113

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.

pilcrow
  • 56,591
  • 13
  • 94
  • 135
  • 5
    Yeah, I couldn't answer my own question, but you've got the right info out of my my comments above. FWIW: it's also worth doing a `ls -al@` on the file to see the `com.apple.quarantine`. – Nick Mar 31 '12 at 03:27
  • 2
    Ha. I found that solution *without* reading your comments. That'll teach me to refresh more often. – pilcrow Mar 31 '12 at 03:29
  • 6
    For reference, if you realize you have a whole directory tree with the `com.apple.quarantine` attribute, run `xattr -dr com.apple.quarantine .` from inside the directory to clean all files within it. I got a mass-quarantined directory like that by unzipping a zip file I had copied over a local network. – Rory O'Kane May 07 '12 at 20:21
  • 1000X this! Thanks. My slightly changed solution was `xattr -rd com.apple.quarantine [path to where shit hit the fan]` – Jason Kim Nov 02 '12 at 20:46
  • 2
    The com.apple.quarantine might also be set on the Disk Image, causing it to be mounted with quarantine. – eile Mar 14 '13 at 15:14
  • 1
    For sparse images, I did not find the `com.apple.quarantine` attribute on the sparsebundle itself but it was hiding on a file inside the bundle. The `-r` flag was necessary to clear the attribute. – jrc Oct 06 '13 at 12:16
  • When running this through an application environment I'm having error: xattr: [Errno 1] Operation not permitted: [file path]. Is there any command I can use to fix this? – Santanu Karar Jun 03 '16 at 08:46
  • I got the quarantine attribute even though I created the file from the command line with "bbedit filename.sh". Crazy. (Yes, BBEdit is GUI, but it's a dev tool, so I would have expected something more dev-friendly than this trap) – hmijail Jun 14 '19 at 06:18
  • Ugh, do NOT use textedit. Super annoying "feature". – wordsforthewise Nov 17 '21 at 08:26
15

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.

KPM
  • 10,558
  • 3
  • 45
  • 66
  • 1
    If it is a sparse bundle, also check the files inside. E.g. in my case the `token` file inside had the quarantine flag and I had to do: `xattr -d com.apple.quarantine /path/to/disk_image.sparsebundle/token` – Binks May 25 '19 at 15:43
6

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

More Info:Resolved Operation not permitted

Javen.Yang
  • 181
  • 2
  • 3
0

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

Mat Gessel
  • 562
  • 8
  • 17
0
-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
larsks
  • 277,717
  • 41
  • 399
  • 399
  • The advantage of using `#!/usr/bin/env perl` is that it uses your PATH environment instead. So that if you have multiple interpreters on your system, it uses your preferred one. – njh Jul 16 '19 at 13:06
-2

1.delete "node_modules" folder 2.npm install

Ge Hu
  • 1