4

I just started using Linux. I'm using Ubuntu and I think I made a very grave mistake. I made a script and by some stupid sense I decided to move it to my /bin folder, but I accidentally typed

mv /home/kenny/script /bin/bash

Now I have lost my bash and don't know what to do. Every time I run bash I get a "too many symbolic links" error.

What can I do to restore my /bin/bash?

  • Just in passing - the usual place to put your own programs (including scripts) is in /usr/local/bin. I find that putting my own scripts there helps me keep track of what's mine and what belongs to packages. (and I give write permission to my admin group - who can't write to /bin or /usr/bin...) – Toby Speight Sep 3 '15 at 17:26
1

You can try running /bin/sh instead.

After that, reinstall bash:

sudo apt-get install --reinstall /bin/bash

This should fix your error.

  • sh isn't working...it says sh isn't installed. So I installed it but I got a dpkg-preconfigure error – kenny Sep 3 '15 at 15:49
1

The main shell used by the ubuntu system itself is /bin/dash.

So try to run that. It has no features for interactive use like completion, but it's a full shell in terms of basic shell features.

You already commented that /bin/sh is missing, which is a symbolic link to /bin/dash.
Either the link, or the dash binary is missing.

But I would expect that Ubuntu can not do much without dash, and it seems to be still up - so we can hope hope /bin/dash is there.
Maybe some scripts in of the system are made to run with dash, but specify to use sh, which is now missing.

You could recreate the symbolic link /bin/sh pointing to /bin/dash by:

sudo ln -s -r /bin/dash /bin/sh

The system itself does not need bash - all scripts that are part of the Ubuntu system should run with the features of dash.

Only interactive terminals run bash by default, and it's required by custom scripts when they start with the line #!/bin/bash.

Other shells to try:

  • /bin/zsh
  • /bin/csh
  • /bin/tcsh
  • /bin/mksh
  • /bin/lksh
  • Thank you dash works but now I'm having trouble installing. apt-get install gives error – kenny Sep 3 '15 at 16:59
  • Ok - add the error message to the question. You could recreate the link /bin/sh by sudo ln -s -r /bin/dash /bin/sh. – Volker Siegel Sep 3 '15 at 17:35
  • @kenny you may need to temporarily create a symbolic link from dash to bash i.e. using a dash shell, sudo ln -s dash /bin/bash: this should be enough for the replacement bash package's install scripts to run and thus allow you to re-install the "real" bash. Yes I have tried it once for fun. – steeldriver Sep 3 '15 at 17:37
  • @steeldriver Good point, but that command needs to be run in the directory /bin to create the link there. – Volker Siegel Sep 3 '15 at 17:43
0

Check if you have bash in /usr/bin/.

If so, if it's like on my distro, then /bin is a link to /usr/bin/; so with any hope you only have crashed /bin/bash with your mv, and can restore it from /usr/bin/

  • If he wanted to put anything in /bin, he must have had root access. Hence, the problem isn't using root rights, but rather a simple mistake. – MatthewRock Sep 3 '15 at 15:23
  • Its not there in /usr/bin...and I know and lesson learnt, don't go messing with sudo. – kenny Sep 3 '15 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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