Currently Being ModeratedFeb 14, 2012 10:27 AM (in response to galfenol)
See this TextEdit quarantines files its been reported since 10.7.3 came out.
Google textedit quarantine you'll get a bunch of hits.
However, there appears to be a bug in the latest version of OS X Lion in which the quarantine flag is attached to existing files on the system, preventing some code such as user scripts from being executed. If you create shell scripts, for instance, then opening them in TextEdit and making changes to them will result in them no longer being executable and will result in an "Operation not permitted" error in the Terminal.
Currently Being ModeratedFeb 14, 2012 11:02 AM (in response to galfenol)
The solution is simple. Don't use TextEdit to edit scripts.
Currently Being ModeratedFeb 14, 2012 11:12 AM (in response to Linc Davis)
I would suggest trying TextWrangler to edit his scripts, assuming he wants a GUI editor.
TextWrangler (free download)
PS. Linc was definitely on the right track to suspect the quarantine attribute as the root cause of the problem.
Currently Being ModeratedFeb 14, 2012 4:17 PM (in response to Frank Caggiano)
Running the find to remove the exteneded attributes did not remove the quarantines from the scripts.
Currently Being ModeratedFeb 14, 2012 4:30 PM (in response to galfenol)
Yes it did. I've tested that command, and it works. When you open the scripts in TextEdit, as we now know, the attribute is restored.
Currently Being ModeratedFeb 14, 2012 5:31 PM (in response to Linc Davis)
Thank you everyone who contributed to debugging this issue. I am now getting used to TextWrangler, which has some nice features, like running scripts from within the editor. All the best.
Currently Being ModeratedFeb 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
Pandora:bin jdaniel$ ./hw.sh
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.
Currently Being ModeratedFeb 15, 2012 5:09 AM (in response to etresoft)
On both machines running 10.7.3 where I have this (TextEdit) problem, my accounts are in the Admin group.
Currently Being ModeratedFeb 15, 2012 5:13 AM (in response to galfenol)
Same here, when I reproduced this yesterday it was in an admin account also. Definitely a bug in TextEdit.
Not a total loss I think you'll like TextWangler. It has some nice features.
Currently Being ModeratedFeb 15, 2012 5:54 AM (in response to Frank Caggiano)
It is not a bug in TextEdit. I can create scripts using TextEdit and execute them. The files still have the quarantine flag. Whatever it is, is something else.
Currently Being ModeratedFeb 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
admac:Desktop frank$ ls -l@ foo.sh
-rwxr--r--@ 1 frank admin 24 Feb 15 09:38 foo.sh*
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?iMac 3.06ghz 8gb 1 TB, Mac OS X (10.7.3), Aperture 3.2.2
Currently Being ModeratedFeb 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.
Currently Being ModeratedFeb 15, 2012 9:43 AM (in response to galfenol)
It might be a good idea to learn your way around vi. That is what I normally use for command-line editing. I only use TextWrangler if I am really heavy into something and/or need its particular talents.
Currently Being ModeratedFeb 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.
Currently Being ModeratedFeb 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