which shell to learn "Shell programming"?!

Dominic Mitchell dom at happygiraffe.net
Sat Nov 23 21:51:43 GMT 2002


On Wed, Nov 20, 2002 at 08:31:41PM +0000, Bruce M Simpson wrote:
> Bash programming considered harmful. 
> 
> A number of people in the organisation I currently work for write their
> scripts for bash only, because Linux is usually what they have installed
> on their desktop systems.

Generally, I agree.

> Needless to say I don't condone this practice in any way, because if you
> want your scripts to be portable between operating systems, one shouldn't
> rely on non-standard shells.
> 
> sh, on the other hand, is specified in several POSIX standards, so it's a
> fair bet if you stick to Bourne sh, your scripts will work on production
> UNIX systems such as FreeBSD and Solaris, and even more exotic embedded
> and realtime variants such as QNX and VxWorks.

It does beg the question though, how far back do you go for sh
compatibility?  Not all /bin/sh are POSIX compatibile, denying you
things like:

    $(( ))
    $( )
    Arrays
    ${foo##*/}
    ${foo:-bar}
    foo () { ... }

Yes, the latter two are non-standard before POSIX.  The 7th Edition
/bin/sh does not support them, and subsequently many vendor revisions do
not.

In general, I would write shell scripts that work for your and port them
as needed.  Whilst you should be aware of bash/posix differences (use
".", not "source"), don't fret too much over them.

-Dom




More information about the Ukfreebsd mailing list