Portability of shell scripts from other *nixes

mikel king mikel.king at olivent.com
Thu Jan 26 04:27:05 UTC 2012

On Jan 25, 2012, at 5:08 PM, Doug Poland wrote:

> Hello,
> I'm trying port some shell scripts to FreeBSD that were originally
> written on Darwin (OS X).
> The issue I'm having is the shebang line of the scripts in OS X is
> #!/bin/sh, and it turns out that is really an instance of bash, and
> the code contains some bashisms.  On FreeBSD I have bash in
> /usr/local/bin/bash.
> Is there an "easy/best" way to have a single shebang that works on
> both OS's?  I'd rather not change FreeBSD's bourne shell to bash with
> any symlinking of /usr/local/bin/bash to /bin/sh.
> -- 
> Regards,
> Doug

Mac OS X defaults to /bin/bash but things get weird because sh on mac is also bash. Funnily enough a complete separate binary and not a symlink. Anyway, this means things written for the Mac may not work directly on FreeBSD. What I mean is that bash3 syntax is not going to be backwardly compatible with sh. If you wish to retain the bashiness of the scripts then the easiest option would be to install the bash (3.x) port and use env to invoke the appropriate shell on each system.

Mikel King
BSD News Network
skype: mikel.king

More information about the freebsd-questions mailing list