NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: ksh and brace expansion



    Date:        Tue, 28 Jan 2020 14:20:34 +0000 (UTC)
    From:        adr <adr%SDF.ORG@localhost>
    Message-ID:  <alpine.NEB.2.21.2001281359200.29174%sdf.lonestar.org@localhost>

  | in rc/bin/ksh/config.h it's defined POSIXLY_CORRECT,
  | disabling brace expansion, as noticed in main.c:

It is also in the man page:

         o    brace expansion (also known as alternation): in posix mode,
              brace expansion is disabled; in non-posix mode, brace expansion
              enabled.  Note that set -o posix (or setting the POSIXLY_CORRECT
              parameter) automatically turns the braceexpand option off,
              however it can be explicitly turned on later.

If you want brace expansion, you should explicitly do
	set -o braceexpand
in some startup file.   If ksh hasn't gotten itself into POSIX
mode that will make no difference, if it has, then this one
aspect of it (it is a slightly incompat extension to posix, as in
posix "echo a{b,c}d" should output "a{b,c}d" not "abd acd", though
it is not impossible, being widely implemented, that brace expansion,
as an optional facility, might find its way into a future version of
the standard.

  | I don't know if this is on purpose, but if this is the case you
  | have to change ksh(1) where it is assumed that alternation is
  | available.

Where exactly do you mean?   How it works is definitely "on purpose".

I have no doubt but that the documentation could do with improvements
(most doc can) so if you have some specific changes that you believe
should be made (perhaps just "if the braceexpand option is set" or
"assuming that the braceexpand option is set" in appropriate places)
then please submit PRs (one or more) with the specific suggestions
(or even better, a patch).

  | In my opinion, let sh be a posix shell, let ksh be a korn shell.

That is kind of amusing.   The POSIX shell is based upon the Korn
shell (ksh88) - of which our /bin/ksh (which is an old pdksh) is a
re-implemented clone (modulo bugs in each of them).

POSIX did delete (as in fail to specify, while leaving it open for
implementations to include, by reserving some "words" that portable
scripts should never use) some of the more esoteric ksh8 features
(the select keyword, the REPLY variable, the absurdly ugly _ var, and
more) but did retain some of the even worse features (cd -L for example)
that /bin/sh (which started as a clone of the original Bourne shell, but
has had much of what POSIX requires added) does not (will not) support.

kre

ps: I have no idea why anyone would call brace expansion "alternation",
there are no alternatves, nothing really alters, it is just one more, purely
rote (as in the input exactly specifies the output, nothing else influnces
the results) expansion method, which is sometimes convenient in interactive
mode, and simply an abomination in scripts.




Home | Main Index | Thread Index | Old Index