bash scripting across linux and solaris

Matthew Gillen me-5yx05kfkO/aqeI1yJSURBw at public.gmane.org
Fri Aug 28 00:36:41 EDT 2009


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





More information about the Discuss mailing list