scripting

Bennett Todd bet at rahul.net
Tue Jul 13 12:04:39 PDT 2004


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.

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.

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").

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.

-Bennett
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.linuxfromscratch.org/pipermail/lfs-chat/attachments/20040713/b403fe32/attachment.sig>


More information about the lfs-chat mailing list