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.

Trying to run some .sh scripts in a very cut down Ubuntu installation, but I'm getting messages of the following style:

./my_script: 61: [[: not found
./my_script: 61: ==: not found
./my_script: 61: ==: not found
./my_script: 61: ==: not found
./my_script: 67: [[: not found
./my_script: 73: [[: not found

There is obviously something not quite right :)

The script starts with:

#!/bin/sh

Edit

It runs ok if I start it like this:

bash ./my_script

Edit 2

Sorry, that was a stupid question without some more explanation :) This script works fine, unchanged, on some RHEL machines - what do I need to change on the Ubuntu box to get the script to work, without modifying the script?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

You need to make /bin/sh a symbolic link to /bin/bash:

$ cd /bin
$ sudo ln -sf bash sh

This switch may have unknown side effects, because changing this symbolic link makes /bin/bash get used for system script execution instead of /bin/dash. . If you wish, you can always switch back to your original link arrangement.

Ubuntu customized their default shell a bit:

-rwxr-xr-x 1 root root 801808 2010-08-10 15:58 bash
-rwxr-xr-x 1 root root 87984 2010-06-24 16:01 dash
lrwxrwxrwx 1 root root 4 2010-10-16 21:58 rbash -> bash
lrwxrwxrwx 1 root root 4 2010-10-16 21:58 sh -> dash
lrwxrwxrwx 1 root root 4 2010-10-16 21:58 sh.distrib -> bash
lrwxrwxrwx 1 root root 7 2010-10-16 21:58 static-sh -> busybox

It's just a symlink anyway. If it breaks something you need change it back.

Some users have been doing this since 2007 and have experienced little negative side effect. I might not call that insanity.

share|improve this answer
    
Sorry, my question wasn't clear - I need to be able to run the script without changing it - I am happy changing the configuration of the Ubuntu box however. –  Rich Dec 8 '10 at 14:16
add comment

The difference seems quite obvious:

  • When you type bash, you execute bash.
  • When you type ./myscript, it executes sh (the #! line).

If the script uses bash-specific features, it should start with #!/bin/bash (or maybe #!/usr/bin/env bash).

share|improve this answer
    
Sorry, my question wasn't clear - I need to be able to run the script without changing it - I am happy changing the configuration of the Ubuntu box however. –  Rich Dec 8 '10 at 14:15
1  
@Rich: Create a wrapper that does exec bash myscript "$@". There's no other at least remotely sane way. –  grawity Dec 8 '10 at 14:16
    
your launcher script is a way better solution than mine if he won't be using a BUNCH of crossover scripts. if he's looking for more interop in an enterprise type of setting, he might want to change his default shell back to bash. –  hbdgaf Dec 8 '10 at 14:31
    
@aking1012: Changing "default shell" will not affect /bin/sh, which stays the same. –  grawity Dec 8 '10 at 14:33
    
I'm not talking about his default login shell, /bin/sh has just been a symlink to another shell on many linux distros for some time and almost all shell scripts point to it. in this way it is a default shell...just trying to clarify –  hbdgaf Dec 8 '10 at 14:36
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.