Björn Lindberg d95-bli at
Tue Jul 13 14:20:00 PDT 2004

Bennett Todd <bet at> writes:

> 2004-07-13T18:39:49 Björn Lindberg:
> > When using shell, there are two reasonable portability levels:
> > plain Bourne shell or POSIX. Bourne shell is the lowest common
> > denominator, but I would guess that virtually every modern Unix
> > environment supplies at least one POSIX-compliant shell in
> > addition to the Bourne shell.
> Since ksh has attempted to swing around to being more Posixy, I
> expect you're right.

I had the impression that it is the POSIX shell standard that is more
or less based on ksh (or rather, based on Bourne shell but
incorporating ksh extensions at the time). Bash in turn derives most
of its beyond Bourne-extensions fron ksh. I believe that ksh88 is
quite close to POSIX in that it is both compliant, and does not have
too many extensions of its own.

> My _real_ problem is that I've not yet gotten around to learning the
> portable POSIX shell features over and above c. 1990-vintage
> /bin/sh. I include shell functions in my portable dialect, for
> instance.

Ah, I see. I learnt shell more recently, so that was never my
problem. :-)

> And some of my habits are pure curmudgeounly accomodations to
> ancient stuff, no longer to be found on any modern system. I never
> liked the "[" link to test, for instance, to I spell out "test". I
> never did figure out exactly when shells got fixed so "$@" would
> expand to no args when $#==0, so I still use the cranky ${1+"$@"}.
> > [ a brace of awks of varying freshness ]
> > I imagine there are similar problems with Perl too, since old
> > installations may have older Perl versions than currently is
> > available?
> There sure are, you betcha. And for no good reason, I've got no
> consistency at all on this issue. Whereas I strive to always code in
> a dialect of Bourne Shell that pretty much works unchanged with
> #!/bin/sh on everything I've seen for many years, I'm pretty
> unblushing about coding to whatever is the oldest perl I still have
> on any of my own machines. Before too much longer that's going to be
> something in the 5.8 series:-).
> > > 	perl -e 'rename "file $_","file.$_" for 1..20'
> > 
> > I don't use Perl. I would instead use awk or shell or a
> > combination thereof.
> I should have mentioned, a _lot_ of times I'll write perl that
> prints sh commands to stdout, run it once to make sure I like the
> results, then run it again piping it into sh, often with -xe. (as
> you say, "or a combination thereof").

That is a convenient way for one liners. I've done that sometimes with
awk. It is good since it is easy to debug, and then run.

> So many different idioms.
> Could you point at a good reference for the main portable POSIX
> shell enhancements over and above Bourne Shell classic? I've never
> been interested in pursuing bash-specific or ksh-specific advanced
> features, but the newer plateau of portable shell does sound
> reasonable. At least I should be able to _read_ it with confidence
> even if I decide to continue speaking in an antique dialect myself.

Sorry, not really. Just because you asked, I did a quick Google
search, and came up with the following, which might be helpful:

Also as I said, I think ksh88 is quite close to POSIX. For me, when I
learnt shell programming I followed where there are
quite a number of knowledgeable people who sometimes discuss these
portability issues in almost sickening detail. Both asking questions
and perusing the archives is helpful, but probably way to much work
for someone who just want to get up to speed on POSIX.


More information about the lfs-chat mailing list