Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

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

/bin/bash: cannot excute binary file

I was changing paths and I think I screwed up. My terminal shows


"/bin/bash: /bin/bash: cannot execute binary file"


when it opens


Help?

MacBook Pro, Mac OS X (10.6.8)

Posted on Jun 27, 2011 3:45 PM

Reply
22 replies

Nov 4, 2017 7:23 AM in response to randallin

I was also getting the same error. I was using TextWrangler to write the script and after that saving and giving execution permission to file.

But I was getting error "bash- can't execute binary file".

When I tried printting the file contents on terminal, i found that TextWrangler is somehow adding "??" text in the start of my file. Instead of script starting by "#!/bin/bash" , it was "??#!/bin/bash".

I again created the script using vim.

After that it was running fine.

So, always check the contents of script in terminal, if you are using any other text editor.

Jun 27, 2011 5:59 PM in response to randallin

If you were changing paths then presumably you were changing the definition of the PATH shell variable. So look in your bash setup files in your home dir. These include ~/.bash_login, ~/.bash_profile, ~/.profile, ~/.bashrc. These are dot files so you won't see them in the finder and not all of them are necessarily present.


Of course somehow (have no idea how) your permissions may have been screwed up for the /bin directory . If that is the case do a sudo chmod 755 /bin/bash. Does other stuff in your /bin directory launch? Indeed, if the permissions are screwed you wouldn't even be able to do the chmod since it's in /bin too! If permissions are screwed then do a repair permissions from Disk Utility (in fact maybe you should just do that first).

Jun 27, 2011 6:02 PM in response to X423424X

I see ~/.profile which is the same as what I had before.


To be clear I was trying to change PATH for a Matlab terminal. Matlab can open up a terminal with system('command') and within this I say the PATHs were not the PATHs I had normally. It would not accept PATH changes either.


A colleague suggested that I create an alias or link there. I think I copied the dir instead and then rm -r 'd it. This is when the error occurred.


I have now installed a new bash via macports which exists elsewhere. It works. Is there anyway I can overwrite my old bash or something with that?


Thanks!

Jun 28, 2011 10:32 PM in response to randallin

As I stated in my first reply the executable binary for bash is /bin/bash. Replace that and you've replaced bash. But I don't recommend it. You are then replacing a apple supplied system file. As soon as any system update comes along (e.g., a combo updater, maybe even the notorious 10.6.8 combo update, wouldn't know, I'm sticking with 10.6.5) there's no guarantee that your file will won't be clobbered with the update. It's your call of course.

Jun 29, 2011 12:59 AM in response to randallin

/opt ??? I guess that's something created by or for macports. Personally I would use /usr/local/bin.


I'm still curious what wrong with your original /bin/bash. If you can put your version of bash most anywhere and it executes ok then I would be wondering what happened to the original /bin/bash. Do the following two terminal commands and post the results:


file /bin/bash

ls -l /bin/bash

Jun 29, 2011 6:20 AM in response to randallin

Get Pacifist

<http://www.macupdate.com/info.php/id/6812/pacifist>

and use it to extract a fresh copy of bash from your installation DVD


/opt/local is where MacPorts.org puts its stuff, just as Fink.sf.net puts its stuff in /sw. In both cases it means they do not interfere with typical open source installations. You as a user get to choose via your PATH, shell aliases, shell functions, and personal shell scripts which version of a package you use (MacPorts, Fink, Open Source, Mac OS X).


But as has been suggested, you do not really want to replace anything normally installed by Mac OS X, as you never know if it is exactly the same as what was there, and if Mac OS X has some script it needs during normal operation that would break if you replace the Mac OS X version.


And with that in mind, and considering the importances of 'bash' it might be very wise to either use Pacifist, or reinstall Mac OS X so that you have a clean 'bash' copy.

Jun 29, 2011 9:57 AM in response to randallin

When the Terminal starts up it by default runs a new login session (/usr/bin/login). Try going to the Terminal's preferences to change this so it runs just the "/bin/bash" command (or another shell: csh, sh, zsh, etc.). If this results in no error, then you can try adjusting permissions on the login command, ensuring everyone has both read and execute permissions on it. You might also try doing this for /bin/bash as well, if the problem continues even after making this settings change.


If you cannot get to the command prompt with Terminal, you can use Apple's X11 implementation to run xterm and make the changes from there.

Jun 29, 2011 11:24 AM in response to randallin

Pacifist -> Open Apple Install Discs (don't forget to put your installation DVD into your DVD drive)


OSInstall.mpkg (Pacifist window title)

-> Package Contents (tab)

-> Contents of OSInstall.mpkg

-> Contents of EssentialSystemSoftware

-> Contents of EssentialSystemSoftwareGroup

-> Contents of BaseSystem.pkg

-> bin

-> bash


Click install


Message was edited by: BobHarris

Jun 29, 2011 11:46 AM in response to randallin

Name-MacBook-Pro:~ name$ file /bin/bash

/bin/bash: data <----------------- not correct

Name-MacBook-Pro:~ name$ ls -l /bin/bash

-rwxr-xr-x@ 1 root wheel 33966 Jun 27 15:18 /bin/bash

Name-MacBook-Pro:~ name$


Well there's your problem!


That file command is reporting that it thinks /bin/bash is data instead of an executable mach-o file. On my 64-bit Intel Mac Pro it's a universal (fat) binary for 32 and 64-bit x86 architectures. The output from the file command should look similar to this:


/bin/bash (for architecture x86_64): Mach-O 64-bit executable x86_64

/bin/bash (for architecture i386): Mach-O executable i386


So as mentioned above in this thread you could fish out a replacement copy of bash from the installer with Pacifist. Or simply replace /bin/bash with the working copy you got from macports (that way you won't care if some future update clobbers it with a fresh apple supplied copy).


But if I were you I would ask myself the question: how did bash get clobbered in /bin in the first place and what else may be clobbered in there?

/bin/bash: cannot excute binary file

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