bug-bash
[Top][All Lists]
Advanced

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

Re: declare -f does not output esac pattern correctly


From: Martin D Kealey
Subject: Re: declare -f does not output esac pattern correctly
Date: Thu, 29 Feb 2024 03:39:51 +1000

On Tue, 27 Feb 2024 at 18:48, Oğuz <oguzismailuysal@gmail.com> wrote:

> On Tuesday, February 27, 2024, Martin D Kealey <martin@kurahaupo.gen.nz>
> wrote:
>
>> I've been thinking for a while now that POSIX made a mistake when it
>> permitted ';;' before the closing 'esac'.
>>
>
> I think that decision was made before POSIX. Besides it's handy when
> generating case clauses on the fly, you may not always know which case is
> going to be the last. You may not always know that at least one clause is
> going to be generated either, but `case x in esac' is valid, so it's not a
> problem. The syntax for the case command is neat as-is.
>

Oh I'm well aware that it's "easier for humans", to have a consistent
terminator, but it's a horrible wart from a parsing point of view. There's
exactly one word that cannot be an unquoted pattern, and that's crazy.

Another approach could have been to have an initiator keyword or symbol,
rather than a terminator.
If you squint closely, 'in' and ';;' have pretty much the same purpose, so
if we were simply replace 'in' with ';;' we would get:

case $thing
  ;; a) echo A
  ;; b) echo B
  ;; c) echo C
esac

Which is nice and regular, just like you're asking for.

And arguably it makes more sense for the flow-through symbol to be as
obvious as possible:

case $thing
  ;;  *a*) echo has A
  ;;& *b*) echo has B
  ;&  *c*) echo has B or C
  ;;  *d*e* | *e*d* ) echo has D and E
esac

-Martin

PS: yes that's even more ugly than the current syntax, but it *is* more
regular. And no, I don't think we can convince POSIX to allow it.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]