Re: [PATCH] Supplant the "while case ... break ;; esac" idiom
- From
Miles Bader <miles@gnu.org>
- Date
- Sep 24, 2007, 13:45 UTC
- Message-ID
- <87k5qgrxcu.fsf@catnip.gol.com>
- In-Reply-To
- <20070924113556.GI8111@void.codelabs.ru>
Eygene Ryabinkin <rea-git@codelabs.ru> writes:
Show 7 quoted lines
>> The comment "... holds only for a shell where [ is a builtin" doesn't >> make any sense to me > > The 'while case ...' construct does not invoke any external commands. > The 'while test ...' too, but only when 'test' is builtin. When > 'test' is the external binary you get one additional fork/exec per > each cycle.
In practice that's not an issue though -- every reasonable shell has test as a builtin these days, so the "works when test is not a builtin" criteria is really important only for robustness.
> I believe that this trick comes from the old days where people were > generally much more eager to save CPU cycles than now ;))
Yes. I still occasionally find myself using "case" where if+test might be more natural, but I think it's basically an anachronism these days, and causes more harm by reducing readability than good.
-Miles
-- The car has become... an article of dress without which we feel uncertain, unclad, and incomplete. [Marshall McLuhan, Understanding Media, 1964]