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?

link|improve this question

63% accept rate
feedback

2 Answers

up vote 1 down vote accepted

Try changing bin/sh to bin/bash

to address the last edit to the question...you need to make /bin/sh a symlink to /bin/bash
ubuntu customized their default shell a bit...this may have other side effects though, be careful

-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.

in answer to grawity "There's no other at least remotely sane way."

according to: http://ubuntuforums.org/archive/index.php/t-499045.html
some users have been doing this since 2007 and have experienced little negative side effect...i might not call that insanity

link|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
feedback

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).

link|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
@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. – aking1012 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 – aking1012 Dec 8 '10 at 14:36
feedback

Your Answer

 
or
required, but never shown

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