Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bash scripting across linux and solaris



On 08/26/2009 05:49 PM, David Rosenstrauch wrote:
> On 08/26/2009 05:45 PM, Stephen Adler wrote:
>> Hi all,
>>
>> I'm writing a bash script which I would like to execute the same script 
>> on a linux and a solaris system. but my problem is that the bash 
>> executable is in /usr on linux and /usr/bin on solaris. So how do I 
>> define the first line #! syntax so that the shell which is executing the 
>> script knows where to pick up the executable.
> 
> Can't you just use:
> 
> #!/bin/sh

No, because that shell hasn't been bourne again! :-P
Strictly speaking, 'bash' is a superset of 'sh'.  Some linux systems make
'sh' a symlink to 'bash', but not all (ubuntu IIRC is one that doesn't), and
solaris certainly doesn't.

This matters since a linux distro like fedora that just uses bash for sh
will not enforce 'sh-only' syntax, whereas ubuntu and solaris, which use
actual 'sh' binaries, will.

>From the school of hard knocks: unless you're an expert 'sh' programmer,
don't develop scripts that start with #!/bin/sh on fedora and the like,
since you can't be sure they'll work on systems that actually use the shell
you're telling it to use.

Matt






Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org