2

I mistakenly copied two files over /bin/bash. This now made my terminal non-responsive. I've followed this tutorial but it didn't help.

For reference, the files are runcocoa.sh and runc.sh to be specific, from this tutorial). I also copied them to /usr/local/bin, but then I deleted them…

How can I restore the functionality of my system?

1
  • Have you tried another terminal emulator, like iterm or cathode? Jun 27, 2013 at 12:57

2 Answers 2

5

I went to Terminal » Preferences » Startup and changed Shells open with from Default login shell to Command, and used another shell (e.g. /bin/csh rather than my original /bin/bash).

This made my terminal functional again – and using this tutorial, I installed a newer version of Bash to replace the /bin/bash I originally overwrote.

I cut and pasted these lines:

curl -LO ftp://ftp.cwru.edu/pub/bash/bash-4.2.tar.gz
tar zxvf bash-4.2.tar.gz
cd bash-4.2
./configure && make && sudo make install
chsh -s /usr/local/bin/bash {user_name}
sudo bash -c "echo /usr/local/bin/bash >> /private/etc/shells"
cd /bin
sudo mv bash bash-old
sudo ln -s /usr/local/bin/bash bash

And done!

6
  • This only fixes your symptoms, not the actual problem. Changing the system-default Bash 3.x to 4.2 might have you run into other issues as you go … You should rather save your data and reinstall OS X, or restore from a Time Machine backup.
    – slhck
    Jun 27, 2013 at 13:10
  • @slhck ugh.. that's hardly comforting.. but what i didn't understand is how can simply copying a file into a certain location cause so much damage to my terminal? isn't that action undoable (assuming i can locate those files)? reinstalling osx seems like an overkill
    – abbood
    Jun 27, 2013 at 13:17
  • You did not just copy, you overwrote /bin/bash and so deleted bash from your system. The terminal works through bash so if there is no bash you get no terminal. You should be able to reinstall the bash you deleted by replacing bash-4.2.tar.gz in the FTP URL in your answer with the appropriate bash version for your system or copy /bin/bash from your backup. I don't OSX but this should work. @slhck am I wrong?
    – terdon
    Jun 27, 2013 at 15:48
  • 3
    I upgraded my /bin/bash to 4.2 a while ago (Mt. Lion) and haven't had any issues. I kept a backup of the original (of course) in case anything came up, but 4.2 seems backwards-compatible enough that any system scripts relying on it haven't failed, to my knowledge.
    – MattDMo
    Jun 27, 2013 at 15:55
  • @terdon If the OP only overwrote that, of course it can be put back from a backup easily. It wasn't clear what exactly they did in the first place, so I took the safe route :)
    – slhck
    Jun 27, 2013 at 19:05
1

As mentioned in the other answer, you can use Terminal by changing the command that shells open with to something like /bin/sh:

The /bin/sh and /bin/bash binaries are almost identical, so you can just copy /bin/sh over /bin/bash.

$ diff -y --suppress-common-lines -W 80 <(strings /bin/bash) <(strings /bin/sh)
                                      > /bin/bash
${FCEDIT:-${EDITOR:-ed}}              | ${FCEDIT:-ed}
@(#)PROGRAM:bash  PROJECT:bash-86.1   | @(#)PROGRAM:sh  PROJECT:bash-86.1

Most of the differences between /bin/sh and /bin/bash depend on the name the shell was invoked with. On other platforms /bin/sh is a symlink to /bin/bash. See this question.

The recovery partition also includes a bash binary. It's smaller because it doesn't support i386, but it was identical with the binary created by lipo -thin x86_64 /bin/bash -output /tmp/bash on my installation.

$ diskutil mount 'Recovery HD'
$ hdiutil mount /Volumes/Recovery\ HD/com.apple.recovery.boot/BaseSystem.dmg
$ stat -f %z /bin/bash /Volumes/OS\ X\ 10.8.2\ Base\ System/bin/bash
1333920
699040
$ file /bin/bash
/bin/bash: Mach-O universal binary with 2 architectures
/bin/bash (for architecture i386):  Mach-O executable i386
/bin/bash (for architecture x86_64):    Mach-O 64-bit executable x86_64
$ file /Volumes/OS\ X\ 10.8.2\ Base\ System/bin/bash
/Volumes/OS X 10.8.2 Base System/bin/bash: Mach-O 64-bit executable x86_64
$ lipo -thin x86_64 /bin/bash -output /tmp/bash
$ stat -f %z /tmp/bash
699040
$ diff /tmp/bash /Volumes/OS\ X\ 10.8.2\ Base\ System/bin/bash
$ 
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .