• Re: Is ksh93 (or 2020) really better than bash? (Was: awk functionality

    From Janis Papanagnou@21:1/5 to Kenny McCormack on Thu Feb 17 23:38:32 2022
    [ crosspost to CLA removed ]

    On 17.02.2022 22:25, Kenny McCormack wrote:
    [...]

    But what I'm really wondering about is whether it makes sense to switch to ksh from bash for my day-to-day shell scripting. I'm pretty familiar and comfortable with bash at this point; I'd rather not switch unless there was
    a good reason.

    My guess would be that it's not necessary if you don't mind the speed degradation of bash and had not yet need for any of the advanced ksh93 features.


    The system that I am typing on right now has /usr/bin/ksh as a link to /usr/bin/ksh2020 - which is, presumably, 27 years better than ksh93

    If I read what this 2020 thing actually is, I wouldn't bet on that.[*]
    And also mind that version "ksh93u+" is from Aug 2012, quite "new".

    What has to be said about the quasi-standard ksh93u+ is that it has a
    couple nerving bugs in interactive use (that may be considered as being irrelevant if used only for scripting). If you want to switch I'd surely suggest to use the derived version ksh93u+m (see the announcement post
    from Marijn Deckker, Dec 2021, in this newsgroup); this works flawless
    it seems, the author seems to have spent a lot effort in bug-fixing.

    (if you
    see what I mean...). I'd like to hear from people knowledgeable on both shells as what kind of advantages ksh has over bash.

    Speed, features, always leading inventor of useful new features.[**]

    Enumerating the features is cumbersome, since bash was trying to catch
    up over the time, and a feature missing in earlier bash releases might
    now be part of it. Off the top of my head: FP-arithmetic and a lot of
    the C-lib functions, arithmetic for-loop, arithmetic command, command
    negation, more [[...]] tests, many variable expansion variants, a lot
    of performant builtins, extended patterns are standard, IO-redirections
    to seek and skip in files, scope in functions (visibility, signals,
    getopts, ...), name references, so called discipline functions (that
    can be associated with variables to trigger actions on read/write/...),
    data type definitions, extended printf controls, support for shell and
    regexp patterns, ANSI quoting, the extremely powerful getopts, and
    certainly I forgot to mention many many more.

    If you used in your scripts the few bash-specifics (that ksh typically
    supports in another form) these programs may break (unless you use #! mechanics).

    One thing to also consider for a decision is that bash, as standard
    shell and inherent part on Linux systems, will probably be continued,
    while I don't know the plans for ksh93u+m (and AT&T's branch ksh93u+
    is a dead end anyway, I suppose).


    The one that I am aware of is floating point math handled natively in the shell. This is a significant thing, and one I often miss in bash. I see
    no particular reason why it could not be implemented in bash.

    Indeed. And I am wondering why over that long period of time it's
    not yet been implemented in bash, since the syntactic context is
    quite localized, mainly in $((...)), ((...)), and for((...)) loops.

    In fact,
    I've worked up a system where I run "bc" as a co-process that works pretty well. Note that if you Google "floating point in bash", you'll get lots of suggestions to use "bc", but none (AFAICT) mention running it as a co-process. That seems to be my innovation.

    LOL. Think about it. In the early 1990's I used ksh88, which did
    support co-processes already, but didn't support FP-arithmetic.
    What do you think is the straightforward workaround for ksh-users
    at that time? ;-)

    Janis

    [*] https://en.wikipedia.org/wiki/KornShell :
    KornShell, i.e. ksh2020, a "major release for several reasons"
    (such as removal of EBCDIC support, dropped support for binary
    plugins written for ksh93u+ and removal of some broken math
    functions), was released by AT&T, but is not maintained or
    supported (by AT&T; wasn't even on release date).

    [**] The latter isn't true any more since the labs fired the authors
    and discontinued development. If you follow the ksh93u+m path it's a
    different situation, though.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Janis Papanagnou on Fri Feb 18 12:05:37 2022
    On 17.02.2022 23:38, Janis Papanagnou wrote:
    On 17.02.2022 22:25, Kenny McCormack wrote:
    In fact,
    I've worked up a system where I run "bc" as a co-process that works pretty >> well. Note that if you Google "floating point in bash", you'll get lots of >> suggestions to use "bc", but none (AFAICT) mention running it as a
    co-process. That seems to be my innovation.

    LOL. Think about it. In the early 1990's I used ksh88, which did
    support co-processes already, but didn't support FP-arithmetic.
    What do you think is the straightforward workaround for ksh-users
    at that time? ;-)

    BTW, I was astonished about your statement that Google had no entries.
    so I searched Google Groups for this newsgroup and "co-process" and
    stumbled across the post/reply I appended below, dated Aug 7, 2004.
    It is probably not the first post on that topic and other folks have
    certainly used that co-process principle in context with bc before
    (as I did in the 1990's) without posting about it, but at least it
    seems to stem from a time back when bash didn't support it.

    Janis

    --- quote begin ---

    JQ wrote:
    Would someone be so kind as to explain coprocesses? I don't know if
    bash now supports them of if it's still in Korn's domain. I've never
    quite understood where to best make use and practice of them.

    You may view them as providers for external services that are available
    to your process.

    Say you have some powerful external service like bc's multiple precision integer arithmetic that you constantly want to use. Start the co-process
    and whenever you have a calculation send a message to the coprocess and
    get the answer.

    You may also use it if you want to provide some new user interface to an existing program. You take the user input, maybe manipulate the data,
    then send it to the coprocess, get the response, optionally change/format
    the output to your needs.

    The syntax to use it, if not already known to you, is

    bc |& # create coprocess 'bc'
    while read query?"Enter your data: "
    do
    print -p "${query}" # send message to coprocess
    read -p response #
  • From Christian Weisgerber@21:1/5 to John McCue on Fri Feb 18 18:30:40 2022
    On 2022-02-18, John McCue <[email protected]> wrote:

    Depends, will you ever write scripts for any of the BSDs
    or a proprietary UNIX ?

    If so you may want to use ksh.

    POSIX sh is the much better bet there.

    YYMV on that one, OpenBSD defaults to a ksh88 clone,
    AIX defaults to ksh88. NetBSD seems to default to a ksh
    look-alike and the same now seems to be true for FreeBSD.

    No, FreeBSD has a POSIX sh and does not ship with anything ksh-ish
    out of the box.

    --
    Christian "naddy" Weisgerber [email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Axel Reichert@21:1/5 to Janis Papanagnou on Fri Feb 18 23:53:29 2022
    Janis Papanagnou <[email protected]> writes:

    use the derived version ksh93u+m (see the announcement post from
    Marijn Deckker, Dec 2021, in this newsgroup)

    ... which was also the one I had in mind when asking.

    Axel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John McCue@21:1/5 to Christian Weisgerber on Sat Feb 19 02:30:58 2022
    Christian Weisgerber <[email protected]> wrote:
    <snip>
    No, FreeBSD has a POSIX sh and does not ship with anything ksh-ish
    out of the box.

    Was not sure about FreeBSD with its shell, good to know.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to [email protected] on Sat Feb 19 07:25:52 2022
    In article <supkp2$nsn$[email protected]>,
    John McCue <[email protected]> wrote:
    Christian Weisgerber <[email protected]> wrote:
    <snip>
    No, FreeBSD has a POSIX sh and does not ship with anything ksh-ish
    out of the box.

    Was not sure about FreeBSD with its shell, good to know.

    It is hard to imagine a less relevant point in the context of the thread
    topic.

    --
    The randomly chosen signature file that would have appeared here is more than 4 lines long. As such, it violates one or more Usenet RFCs. In order to remain in compliance with said RFCs, the actual sig can be found at the following URL:
    http://user.xmission.com/~gazelle/Sigs/Rorschach

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)