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

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

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'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.

I had resolved this issue.Open the command file with TextEdit then save it.
More Info:Resolved Operation not permitted

-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

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

1.delete "node_modules" folder
2.npm install

Related

How to run Shell Script using CHMOD in a folder [duplicate]

I simply want to run an executable from the command line, ./arm-mingw32ce-g++, but then I get the error message,
bash: ./arm-mingw32ce-g++: No such file or directory
I'm running Ubuntu Linux 10.10. ls -l lists
-rwxr-xr-x 1 root root 433308 2010-10-16 21:32 arm-mingw32ce-g++
Using sudo (sudo ./arm-mingw32ce-g++) gives
sudo: unable to execute ./arm-mingw32ce-g++: No such file or directory
I have no idea why the OS can't even see the file when it's there. Any thoughts?
This error can mean that ./arm-mingw32ce-g++ doesn't exist (but it does), or that it exists and is a dynamically linked executable recognized by the kernel but whose dynamic loader is not available. You can see what dynamic loader is required by running ldd /arm-mingw32ce-g++; anything marked not found is the dynamic loader or a library that you need to install.
If you're trying to run a 32-bit binary on an amd64 installation:
Up to Ubuntu 11.04, install the package ia32-libs.
On Ubuntu 11.10, install ia32-libs-multiarch.
Starting with 12.04, install ia32-libs-multiarch, or select a reasonable set of :i386 packages in addition to the :amd64 packages.
I faced this error when I was trying to build Selenium source on Ubuntu. The simple shell script with correct shebang was not able to run even after I had all pre-requisites covered.
file file-name # helped me in understanding that CRLF ending were present in the file.
I opened the file in Vim and I could see that just because I once edited this file on a Windows machine, it was in DOS format. I converted the file to Unix format with below command:
dos2unix filename # actually helped me and things were fine.
I hope that we should take care whenever we edit files across platforms we should take care for the file formats as well.
This error may also occur if trying to run a script and the shebang is misspelled. Make sure it reads #!/bin/sh, #!/bin/bash, or whichever interpreter you're using.
I had the same error message when trying to run a Python script -- this was not #Warpspace's intended use case (see other comments), but this was among the top hits to my search, so maybe somebody will find it useful.
In my case it was the DOS line endings (\r\n instead of \n) that the shebang line (#!/usr/bin/env python) would trip over. A simple dos2unix myfile.py fixed it.
I found my solution for my Ubuntu 18 here.
sudo dpkg --add-architecture i386
Then:
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
I got this error “No such file or directory” but it exists because my file was created in Windows and I tried to run it on Ubuntu and the file contained invalid 15\r where ever a new line was there.
I just created a new file truncating unwanted stuff
sleep: invalid time interval ‘15\r’
Try 'sleep --help' for more information.
script.sh: 5: script.sh: /opt/ag/cont: not found
script.sh: 6: script.sh: /opt/ag/cont: not found
root#Ubuntu14:/home/abc12/Desktop# vi script.sh
root#Ubuntu14:/home/abc12/Desktop# od -c script.sh
0000000 # ! / u s r / b i n / e n v b
0000020 a s h \r \n w g e t h t t p : /
0000400 : 4 1 2 0 / \r \n
0000410
root#Ubuntu14:/home/abc12/Desktop# tr -d \\015 < script.sh > script.sh.fixed
root#Ubuntu14:/home/abc12/Desktop# od -c script.sh.fixed
0000000 # ! / u s r / b i n / e n v b
0000020 a s h \n w g e t h t t p : / /
0000400 / \n
0000402
root#Ubuntu14:/home/abc12/Desktop# sh -x script.sh.fixed
As mentioned by others, this is because the loader can't be found, not your executable file. Unfortunately the message is not clear enough.
You can fix it by changing the loader that your executable uses, see my thorough answer in this other question: Multiple glibc libraries on a single host
Basically you have to find which loader it's trying to use:
$ readelf -l arm-mingw32ce-g++ | grep interpreter
[Requesting program interpreter: /lib/ld-linux.so.2]
Then find the right path for an equivalent loader, and change your executable to use the loader from the path that it really is:
$ ./patchelf --set-interpreter /path/to/newglibc/ld-linux.so.2 arm-mingw32ce-g++
You will probably need to set the path of the includes too, you will know if you want it or not after you try to run it. See all the details in that other thread.
I got the same error for a simple bash script that wouldn't have 32/64-bit issues. This is possibly because the script you are trying to run has an error in it. This ubuntu forum post indicates that with normal script files you can add sh in front and you might get some debug output from it. e.g.
$ sudo sh arm-mingw32ce-g++
and see if you get any output.
In my case the actual problem was that the file that I was trying to execute was in Windows format rather than Linux.
Below command worked on 16.4 Ubuntu
This issue comes when your .sh file is corrupt or not formatted as per unix protocols.
dos2unix converts the .sh file to Unix format!
sudo apt-get install dos2unix -y
dos2unix test.sh
sudo chmod u+x test.sh
sudo ./test.sh
I had the same problem with a file that I've created on my mac.
If I try to run it in a shell with ./filename I got the file not found error message.
I think that something was wrong with the file.
what I've done:
open a ssh session to the server
cat filename
copy the output to the clipboard
rm filename
touch filename
vi filename
i for insert mode
paste the content from the clipboard
ESC to end insert mode
:wq!
This worked for me.
Added here for future reference (for users who might fall into the same case):
This error happens when working on Windows (which introduces extra characters because of different line separator than Linux system) and trying to run this script (with extra characters inserted) in Linux. The error message is misleading.
In Windows, the line separator is CRLF (\r\n) whereas in linux it is LF (\n). This can be usually be chosen in text editor.
In my case, this happened due to working on Windows and uploading to Unix server for execution.
I just had this issue in mingw32 bash. I had execuded node/npm from Program Files (x86)\nodejs and then moved them into disabled directory (essentially removing them from path). I also had Program Files\nodejs (ie. 64bit version) in path, but only after the x86 version. After restarting the bash shell, the 64bit version of npm could be found. node worked correctly all the time (checked with node -v that changed when x86 version was moved).
I think bash -r would've worked instead of restarting bash: https://unix.stackexchange.com/a/5610
I had this issue and the reason was EOL in some editors such as Notepad++. You can check it in Edit menu/EOL conversion. Unix(LF) should be selected.
I hope it would be useful.
Hit this error trying to run terraform/terragrunt (Single go binary).
Using which terragrunt to find where executable was, got strange error when running it in local dir or with full path
bash: ./terragrunt: No such file or directory
Problem was that there was two installations of terragrunt, used brew uninstall terragrunt to remove one fixed it.
After removing the one, which terragrunt showed the new path /usr/bin/terragrunt everything worked fine.
For those encountering this error when running a java program, it's possible that you're trying to run a 64-bit java program using on a 32-bit linux operating system.
I only realised when I ran ldd on 64-bit java which reported:
ldd /usr/java/jdk1.8.0_05/bin/java
'not a dynamic executable'
Whereas the old 32 bit java reported sensible results:
ldd /usr/java/jdk1.8.0_05/bin/java
In my case, it turns out the file was a symlink:
$ cat deluge-gtk.lock
cat: deluge-gtk.lock: No such file or directory
$ file deluge-gtk.lock
deluge-gtk.lock: broken symbolic link to 32309
Misleading errors like this are fairly common on Linux. Related discussion: https://lwn.net/Articles/532771/
Give it a try by changing the name of file or folder which is not showing in terminal/command prompt.
step1 : change the name of file or folder.
step2 : cd filename/foldername
For future readers, I had this issue when trying to launch a Django server using gunicorn. I was using AWS CodeBuild to build the virtual environment and run tests and using CodeDeploy to put the built artifacts onto the production server and launch the new version (all environments were Ubuntu 20.04). I had mistakenly thought that env/bin/... contained actual binaries of native libraries but that was not the case. It was just Python scripts with a shebang of the path to the Python interpreter on the build machine. In my case, the machine installing the packages and actually running the packages was different. To be more specific, all of the files in env/bin had the shebang #!/codebuild/output/src715682316/src/env/bin/python, so of course running env/bin/gunicorn on the production server would fail. The cryptic error message was when Ubuntu would tell me that env/bin/gunicorn didn't exist as opposed to saying /codebuild/output/src715682316/src/env/bin/python didn't exist. I was able to fix this problem by starting gunicorn using python3 env/bin/gunicorn instead of env/bin/gunicorn.
In a .sh script, each line MUST end with a single character - newline (LF or "\n").
Don't make mistakes like me, because my text-editor of choice is Notepad++ in Win.

/bin/bash: --timeout: command not found on macos

I'm installing harbor with source code.
✗ make install
the error is below:
...
Successfully built b917c04731a3
Successfully tagged goharbor/nginx-photon:dev
Done.
/bin/bash: --timeout: command not found
make[1]: *** [_build_registry] Error 127
make: *** [build] Error 2
I've tried to get coreutils and config my path
brew install coreutils
Edit :
The answer of #Arne Vogel is more likely to point the real problem.
Indeed it would be surprising that you don't have the command /bin/bash (so the steps I described here won't solve the issue).
coresutil is composed of GNU version of the most famous commands (cat, head, tail, wc, sort...), so it's not directly related to your problem.
You can use brew to install the latest version (version 5) of bash:
brew install bash
Double check if you really don't have a bash inside your /bin/:
sudo ls /bin/bash
It should returns a line like this (pay attention to the permission):
-r-xr-xr-x 1 root wheel 618416 Nov 30 12:55 /bin/bash
If it returns no result, then you may create a link:
sudo ln -s $(which bash) /bin/bash
TBH, I don't know about harbor, but this error seems to be caused by bad formatting in a script, specifically something like:
some-command --some-option --some-other-option \
--timeout
Now if the backslash (to continue the line) is missing, some-command will first be executed (without the --timeout option), and then bash will try to execute a command called --timeout, which, unsurprisingly, does not exist.
This problem can also be caused by an extraneous space after the backslash, a stray semicolon, wrong line terminators (in particular, Windows-style CRLF) etc.
Here are some suggestions for what you could do:
Make sure you have downloaded the source package appropriate for Mac OS X. Many open source packages are distributed in different formats, e.g. .zip and/or .7z for Windows, .tar.gz and/or .tar.bz2 for UNIX. You need either of the latter.
Check the documentation and/or forums, obviously.
If that doesn't help, use ktrace to find the offending script, and then look at it in a text editor. If you do find a bug in a script, consider reporting it to the developers.

dotfiles errors | /Users/marif/.aliases:79: bad option: -t

I am pretty new to OSX but everything is almost settled down, I had configured Z and ZSH earlier and lately come to know about paulirish dot files from https://github.com/paulirish/dotfiles and installed it.
Got to see following output when I refresh .bash_profile or .bashrc
Last login: Tue May 14 08:41:35 on console
ls
➜ ~ ls
Applications Downloads Music Samsung dotfiles log
Desktop Library Pictures Sites install-deps.sh readme.md
Documents Movies Public bin js-boilerplate
➜ ~ z
zsh: command not found: z
➜ ~ source ~/.bash_profile
/Users/marif/.aliases:79: bad option: -t
/Users/marif/.aliases:82: bad option: -t
/Users/marif/.functions:37: parse error near `]]'
/Users/marif/.bash_profile:.:9: no such file or directory: /Users/marif/code/z/z.sh
/Users/marif/.bash_profile:15: command not found: shopt
/Users/marif/.bash_profile:26: command not found: complete
\[\e]2;/Users/marif\[\a\]\[\e]1;\]Users/\W\[\a\]marif at \[\]\w\[\]\[\]\[\]\n$ \[\]
I don't know what's going wrong here, would help if somebody point me out to issue persisting in my profile or something.
zsh is not bash and when I launch "zsh", I see the same error that you do:
[/tmp]:;zsh
ElvisIsAliveAndWell-2% type -t
zsh: bad option: -t
These paulirish dot files are meant to be used with bash. Either use bash or you'll need to port the lines in the dot files that are throwing errors so that they will work in zsh (and if you do this, you can fork or branch or suggest changes to PaulIrish so he can pick up these changes and make them available for other interested folks).

EC2 command line tools

I am trying to setup up Amazon's EC2 service and am having some trouble.
I have downloaded the Amazon EC2 API Tools, which I've put in a folder ~/.ec2 along with my .cert and .pemfiles.
When I attempt any command from ~/.ec2/bin I get an error /Users/zmjones/.ec2/bin/ec2-cmd: /usr/bin/env: bad interpreter: Operation not permitted. I asked about this in "/usr/bin/env bad interpreter".
Now that I have removed the DOS line-endings using variants of this mv /users/zmjones/.ec2/bin/ec2-add-keypair /users/zmjones/.ec2/bin/ec2-add-keypair.bak
tr -d '\r' < /users/zmjones/.ec2/bin/ec2-add-keypair.bak > /users/zmjones/.ec2/bin/ec2-add-keypair, I've tried to execute some of the commands in ~/.ec2/bin and have been unable to get it to work.
I've gotten a permission denied error, which when I then use sudo, tells me that the environment variable EC2_HOME doesn't exist, while echo $EC2_HOME indicates that it does. Here is my ~/.bash_profile.
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:$PATH
PATH=/opt/local/sbin:/usr/local/bin:/usr/x11/bin:/usr/texbin:$PATH
PATH=/usr/local/texlive/2011/bin/x86_64-darwin:$PATH
PATH=/Library/Frameworks/EPD64.framework/Versions/Current/bin:$PATH
EC2_HOME=~/.ec2
PATH=$EC2_HOME/bin:$PATH
EC2_PRIVATE_KEY=`ls $EC2_HOME/pk-*.pem`
EC2_CERT=`ls $EC2_HOME/cert-*.pem`
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home/
export PATH
You're getting a "permission denied" error because the execute (+x) bit is not set on your modified script.
Do not use sudo to fix this.
Simply set the +x bit:
chmod +x /users/zmjones/.ec2/bin/ec2-add-keypair
(and the same for your other scripts with fixed line endings).
The reason sudo didn't work is that by default it starts with a clean environment, without your EC2_HOME and other environment variables.
The reason you don't want to use sudo to fix the problem anyway, is that running with sudo runs the whole program as root, which has the possibility of doing bad things on your system. At the very least, it might create files or subdirectories in your local directory that are owned by root, which you then have to take extra steps to modify/delete later. At worst, a bug in the program could wipe out your whole system, or important parts of it.
If ls -al# shows com.apple.quarantine extended attrib, the files won't be executed. You'll need
xattr -d com.apple.quarantine filename

How can I use mvim to edit my crontab on Mac OS X (10.6.6)

mvim is installed in /usr/local/bin/ but can not be used as either EDITOR or VISUAL:
$ mvim -f # works as expected
$ EDITOR="/usr/local/bin/mvim -f" crontab -e
crontab: /usr/local/bin/mvim -f: No such file or directory
crontab: "/usr/local/bin/mvim -f" exited with status 1
I tried single quotes and using VISUAL instead of EDITOR. Same result. I also tried googling, but apparently the -f flag works just fine for everybody else.
I use Mac OS 10.6.6 and zsh, but the problem is the same in bash.
The problem is crontab expects to be able to run a program called "/usr/local/bin/mvim -f" if you supply that in the EDITOR environment variable.
To get around that, you could write a short shell script. For example, call this one mvimf:
#!/bin/bash
/usr/local/bin/mvim -f "$#"
Then you can run: EDITOR=/usr/local/bin/mvimf crontab -e
I am not sure if this is directly related to the problem you are having but I was seeing a similar error code when trying to edit my crontab. I realized I had a little conflict in my vimrc file related to the pathogen plugin. If you call:
filetype off
when it's already off you can cause problems that will make your Vim exit with errors. Sounds like your issue is fixed already, but since this shows up in searches related to this error code, I thought I would post it here.
Credit goes to commenters on this post - http://tooky.github.com/2010/04/08/there-was-a-problem-with-the-editor-vi-git-on-mac-os-x.html
For those seeing this without mvim, you can use morton-fox's answer for any editor:
EDITOR=/usr/bin/vim crontab -e
Will use vim to open the crontab file

Resources