bug-bash
[Top][All Lists]
Advanced

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

Re: select syntax violates the POLA


From: Greywolf
Subject: Re: select syntax violates the POLA
Date: Thu, 1 Apr 2021 14:40:13 -0700
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0

On 4/1/2021 9:58, Robert Elz wrote:
     Date:        Thu, 1 Apr 2021 11:36:14 -0400
     From:        Greg Wooledge <greg@wooledge.org>
     Message-ID:  <YGXobn5/DqMiuc44@wooledge.org>

   | On Thu, Apr 01, 2021 at 01:36:59AM -0700, greywolf@starwolf.com wrote:
   | >       The following is valid shell code:
   | >
   | >       d=($(ls /usr/src/pkg/*/$1));
   |
   | Syntactically valid, but semantically wrong

Mr. Elz!  Long time!  I remember reading your posts 30 years ago!

[ much other ado elided ]

   | "${d[@]}" with quotes.

Again, yes, but in practice here, not needed.

   | What purpose do the extra curly braces serve?

Good question, wondered that myself.   Note that if they were omitted
the odd syntax issue wouldn't have arisen, as the done would follow "break;"
and be recognised.

Unfortunately the way bash has implemented arrays, $d[@] doesn't do The
Right Thing.

Or do you mean my coding style (which has been valid for over 25 years)?
(why's everyone bagging on my style and ignoring my original point, the
outlying brokenness, anyway?)

I started using the curly braces because every (worthwhile) editor has a
paren-match function which shows you the matching brace at the other
end, and I was tired of searching for which conditional component
(while, if, for, and so on) was missing its closing word.  This helps me
immensely.


After all that, and ignoring select's syntax (it was invented by
ksh, long long ago, and isn't going to change) it is a dumb interface
that can always be coded better using other mechanisms.   And when you
do that you can allow for much more flexible input than just the line
number the select demands.

Indeed, I have written such animals from scratch; I just thought I'd try
out select and was astonished when

select x in ${list}; do {
        break;
} done;

was the only one that failed.


If you avoid select, and avoid arrays, then any Bourne style shell will work.
So, do that.

I will also note that the arrays don't give me grief in the least. :)



kre


Thank you so much for your response!  You got exactly what I was after!

                                --*greywolf;



reply via email to

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