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

Solution 1:

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:

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.