/bin/sh: Illegal option -h

Many a times, while running some scripts one cat get errors like "/bin/sh: Illegal option -h".

One of the reasons for this can be
that in Ubuntu, originally, /bin/sh is symlinked to dash shell instead of the bash shell. This symbolic link makes dash the default shell where ideally bash should be the default shell. Dash is a lighter version of Bash. So some of the scripts ( mind well not all ) can give such errors when run
with dash.

[Edit]:  Please verify that the /bin/sh is a link before removing it. To check do the following first:

              #ls -l /bin/sh

This should give something like following:
lrwxrwxrwx 1 root root 9 2011-07-26 02:04 /bin/sh -> /bin/dash

Please proceed only if you get some prints like this.

So to switch to Bash run the following two simple commands:

    1) sudo rm -f /bin/sh   
   
        This step removes the /bin/sh. Don't worry as /bin/sh is only a symbolic link to the original shell, so actually we are not deleting anything substantial but just a link.

    2) sudo ln -s /bin/bash /bin/sh

        By executing this command we again form a symbolic link of the same name ( /bin/sh ), but this time we link it to the bash shell.
   
    This will make bash as your default shell and now all the scripts you run will be handled by bash.

3 comments:

  1. OK, I did this...and when I restarted the machine it won't reboot! Yikes

    ReplyDelete
  2. This should not happen. This may happen in case you deleted /bin/bash instead of the link. Okay as an precaution measure one should do a

    #ls -l /bin/sh

    and verify that its a link before deleting it.

    ReplyDelete
  3. Could an additional sim link be created pointing to bash (called "shb" or something) then referenced in the config file just for the application in question that is throwing the error? That leaves the original link in place for anything that already is using it to point to dash.

    ReplyDelete