/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)
Apple Event: May 7th at 7 am PT
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)
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.
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).
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!
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.
Ah, makes sense, I think.
Well, I managed to macports in a new bash but it's in /opt/local. I then made terminal start up with that. I understand my actual /bin/bash is still screwed up, but this should be okay right?
/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
Name-MacBook-Pro:~ name$ file /bin/bash
/bin/bash: data
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$
Thanks!
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.
Yeah, that's what I was afraid of, that it would somehow need it in some way. I did used Pacifist, but I just installed terminal.app, which sounds like not what I am to do. How would I extract bash? Just find /bin/bash on Pacifist and replace it?
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.
Yeah, /bin/bash still doesn't work, so changing that doesn't help. 😟
Have you tried changing it to another shell, or using xterm? If that works then you can try adjusting permissions and execuition bits on the bash file. Alternatively you can try running a permissions fix on the boot drive with Disk Utility, which should revert any changes to the BSD commands back to their originals.
I repaired my permissions and changed my shell to the one I installed with macports, located at /opt/local/bin/bash. This works for my purposes, I just don't want a screwed up /bin/bash to result in future errors. How would I adjust the bash file? Thanks!
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
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