Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
Have you tried another terminal emulator, like iterm or cathode? –  Szymon Szydełko Jun 27 '13 at 12:57
add comment

2 Answers

up vote 3 down vote accepted

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!

share|improve this answer
    
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 '13 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 '13 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 '13 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 '13 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 '13 at 19:05
show 1 more comment

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
$ 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.