Apple Intelligence is now available on iPhone, iPad, and Mac!

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

bad interpreter: Operation not permitted on Lion 10.7.3

My unix scripts are now dead, after the upgrade to 10.7.3. A typical error message is /bin/bash: bad interpreter: Operation not permitted Googling this issue shows other people are having build scripts fail and are fixing this by renaming links to libraries. My scripts are simple, they just run an executable, or used to... something like this:

#! /bin/bash

./myprogram << EOF

$1

EOF

MacPlus, SE30, iMacG3, EmacG4, PB G4, iMacG5, PowerMacG5, iMac Intel, Mac OS X (10.7.2)

Posted on Feb 13, 2012 10:07 AM

Reply
Question marked as Top-ranking reply

Posted on Nov 9, 2012 3:21 PM

anticro wrote:


All these answers are useless spam! The only thing that says what's really going on and a solution that works is described here:


http://stackoverflow.com/questions/9952612/mac-os-usr-bin-env-bad-interpreter-op eration-not-permitted


Short: run this command and you should be fine.

xattr -d com.apple.quarantine <YOUR FILE HERE>

thank u so mutch, your solution work and save my time, and of cource i completely agree with u: about 4 pages of useless spam

72 replies

Feb 14, 2012 7:51 PM in response to galfenol

I created a script in TextEdit. This is the result:


Pandora:bin jdaniel$ ls -@Oel hw.sh

-rwxr--r--@ 1 jdaniel admin - 30 14 Feb 22:39 hw.sh

com.apple.TextEncoding 15

com.apple.quarantine 23

Pandora:bin jdaniel$ ./hw.sh

Hello, World


Maybe the problem is your group. I created a standard user account and could finally reproduce your problem by using TextEdit, but not in my normal admin account.

Feb 15, 2012 6:46 AM in response to etresoft

Well I have two 10.7.3 systems, an iMac and MacBook ad they both do it:



admac:Desktop frank$ cat foo.sh

#!/bin/bash

echo script

admac:Desktop frank$ ls -l@ foo.sh

-rwxr--r--@ 1 frank admin 24 Feb 15 09:38 foo.sh*

com.apple.TextEncoding 15

com.apple.quarantine 23

admac:Desktop frank$ ./foo.sh

-bash: ./foo.sh: /bin/bash: bad interpreter: Operation not permitted




Just to be certain you are on 10.7.3? I ask because your profile shows 10.7.2.


One other thing you don't have quarantining disabled on your system?

Feb 15, 2012 9:41 AM in response to Frank Caggiano

I am on 10.7.3. I also get the bad interpreter error when I create a new standard account. I do not get the error in my normal, admin account. Obviously something in my environment is disabling the check. I haven't disabled quarantine as far as I know. I try to keep the system as close to default as possible. However, I do have a few customizations.

Feb 21, 2012 3:12 PM in response to galfenol

I too have been having the same issue, only I think there is something else going on here. I tried editing an ubber-simple Perl script using both TextEdit and VI (actually VIM on the Mac). Both exhibit the same issues with the bad interpreter. I have seen the same behavior when bringing such scripts saved on Windows platforms into a UNIX environment because the Windows editors add the newline character at the end of every line. (Manifests as ^M when viewed in VI; but that does nothing in VIM! So, I tried creating an identical looking script in VIM and saving is right from the Terminal window. After CHMOD to set the execute bits, it ran fine. If I opened the same file in TextEdit.app and added but a single space into the file and saved, the same script was broken again! So next I tried running the now corrupted script through a SED filter, thus:


sed -e "s/^M//g" badscript.pl > goodscript.pl


Run a CHMOD again on goodscript.pl and viola, it now works! This process is repeatable. Thus I believe that TextEdit.app is placing HIDDEN ^M's into the file, and seems to lack an option or Preferences setting to reveal them to us. (Pure VI on UNIX will do this for you, whereas "cat" or "more" command will reveal NOTHING!


I would like to know if someone else here can corrobreate this - or even refute it. I will be glad to hear that it is something other than what I've proposed here. Good dialog though, and a lot of interesting ideas.

Feb 21, 2012 7:01 PM in response to jim505

TextWrangler and Vim will preserve the line ending style of the file it is editing.


TextWrangler -> Edit -> Document Options... allows changing the line ending style. You want to select Unix, as the "Mac (CR)" option is for the Mac Classic OS, not Mac OS X.


In Vim, you can change from DOS to Unix style line ending using


:set ff=unix

Mar 27, 2012 2:51 PM in response to galfenol

Is this the sort of bug Apple are likely to fix? Or are bugs like this not considered that important. After all it's only affecting people accessing Unix or doing things above and beyond web browsing; sending e-mail and watching TV/videos and listening to music.


I came across the bug tonight when trying to do something with EXIFTOOL, having previously modified my script in textedit, as I do from time to time.


I created a brand new file to try and avoid this and then I did the following:

sudo chmod 7777 'name of file' in terminal. However that then simply caused the Operation not permitted error when I then tried to run the script.


A quick and simple task then takes over an hour as I read up on the issue and read the different ways of trying to avoid it or get round it.


I don't do much script writing so I don't see the point of a delicated script editor but I may have no choice if I want an easier life for the time being,


I did wonder what else I've quarantined without realising . I guess it doesn't matter until I hit a problem accessing a file or doing anything with it.


Kind regards

Apr 9, 2012 11:46 PM in response to galfenol

I just figured out why i was getting the output -bash: ./hello.sh: bin/bash: bad interpreter: Operation not permitted when trying to compile a simple script Hello World.


To fix it i had to go to the TextEdit file that I saved as hello.sh and right click, select Get Info and go to select Open with drop down menu and choose and select Open with: TextEdit.


The script run perfectly afterwards.


Please let me know if this also worked for you? If not I can try and advise further.

Apr 10, 2012 5:07 AM in response to anthon9969

yeah... this is something to do with the changes for Gatekeeper I think. I noticed if I save and double click to run files from TextEdit I've gotten prompts saying "TextEdit downloaded this from the internet, are you sure you want to run it" stuff... I'm like... no I just wrote that, it wasn't downloaded... but it doesn't do it all the time.

Apr 10, 2012 6:48 AM in response to doh1231

doh1231 wrote:


I just ran into this problem too... only happens with TextEdit and I've used it for years to edit scripts.

Don't do that. TextEdit is for documents, not UNIX scripts.


yeah... this is something to do with the changes for Gatekeeper I think. I noticed if I save and double click to run files from TextEdit I've gotten prompts saying "TextEdit downloaded this from the internet, are you sure you want to run it" stuff... I'm like... no I just wrote that, it wasn't downloaded... but it doesn't do it all the time.

It has nothing to do with Gatekeeper. That is only in Mountain Lion. If you are working with UNIX scripts, you don't use TextEdit and you don't double-click.

Apr 10, 2012 10:50 AM in response to etresoft

First, don't push your preferences on other people like its some type of right or wrong. I've done quick editing of simple scripts in TextEdit for many years and its never been a problem.... its a text editor after all. Just because you do not like doing that, or it has some features to do more than that doesn't mean it cannot do that. I was adding what I've seen and what is the issue, not asking for anyone's opinion if its the way things should be done.


And yes Gatekeeper is on 10.7.3, including changes to the quarantine system that is causing this issue. I know Gatekeeper cannot be seen in preferences and its disabled by default, but the changes for it is what I'm talking about. If you want to enable Gatekeeper on 10.7.3 you have to use the command line, but it is there.

Apr 10, 2012 1:38 PM in response to doh1231

doh1231 wrote:


First, don't push your preferences on other people like its some type of right or wrong. I've done quick editing of simple scripts in TextEdit for many years and its never been a problem.... its a text editor after all.


TextEdit is a rich text editor that is using the NSDocument system. That is not appropriate for a script text editor. It has too much overhead. The way it saves files is not appropriate for scripting because it will assign extended attributes and arbitrarily reset permission.


And yes Gatekeeper is on 10.7.3, including changes to the quarantine system that is causing this issue. I know Gatekeeper cannot be seen in preferences and its disabled by default, but the changes for it is what I'm talking about. If you want to enable Gatekeeper on 10.7.3 you have to use the command line, but it is there.


That's all well and good, but nobody else has these problems with a true text editor. I don't even have these problems using TextEdit. If you start hacking around on new command line scripts that aren't done yet, all bets are off.

Apr 12, 2012 11:46 AM in response to etresoft

I generally use the tool that is handy and simplest to use. I'm not always in Terminal (thankfully) and I have often used TextEdit to create/edit scripts. It works for me, but I also recognise the features of TextWrangler and use it as well. I was somewhat disappointed when it went to the Apple store and the download from there broke authenticated saves, so I went back to Text Edit for a while. The current version of TextWrangler works well though.


I'm not sure what the point of the whole "do this. don't do that." thing is here. Use the tool that works for you. If it fails, try a different tool.


By the way, vi/vim are a pain if you just want to write simple scripts. I recognize the additional features as potentially awesome (if you can find how to use them) but for simple scripting it really is over kill. Time would tell, naturally, whether commiting to vi/vim would pay off for every/any individual scripter.


There is another command line text editing tool available that is a bit friendlier and way simpler. nano. Give it a try if you haven't. You may find it is the gateway drug that pushes your to vi/vim. 😉

bad interpreter: Operation not permitted on Lion 10.7.3

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.