[colug-432] Portable Shell

Rob Funk rfunk at funknet.net
Mon Oct 19 10:19:15 EDT 2015


jep200404 at columbus.rr.com wrote:
> On Sun, 18 Oct 2015 09:02:43 -0400, Mike Plemmons <mikeplemmons at gmail.com> wrote:
> 
> > What platforms do you want to reach?
> 
> I would like to write scripts that would work on 
> as many Unix and Linux releases as possible of the past 25 years
> with the shells installed by default.
> 
> The focus is on portability
> not features,
> not on being modern.

In that case, aim for POSIX / Bourne sh / dash / ash.

If your aim is just Linux and OSX (and probably whatever commercial
Unices are left today) then bash is fine, but when you include
commercial Unix going back 25 (or 15) years you just can't count on
bash being there. Also BSD tends not to have bash. I think even old
OSX used tcsh instead of bash.

Forget about ksh and its derivatives (including posh), since Linux
doesn't often have those.

If you do target bash or some other non-Bourne shell, be sure to be
specific (e.g. /bin/bash) on the #! line, rather than just specifying
/bin/sh.

It's true that the external commands are likely to be problematic, but
focusing on POSIX can reduce those problems. The trick then becomes
figuring out what's POSIX and what's not, and in some cases figuring
out which path contains the POSIX-compatible commands. (I think it was
/usr/xdg/bin on Solaris, last I looked some 15 years ago.)

Though really, when you go more than about 20 years back, even POSIX
support is dicey, and you start needing to worry about BSD vs System V.



More information about the colug-432 mailing list