bug-bash
[Top][All Lists]
Advanced

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

Re: Incorrect alias expansion within command substitution


From: Chet Ramey
Subject: Re: Incorrect alias expansion within command substitution
Date: Thu, 3 Feb 2022 17:43:25 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.4.1

On 2/3/22 5:25 PM, Robert Elz wrote:
     Date:        Thu, 3 Feb 2022 16:19:08 -0500
     From:        Greg Wooledge <greg@wooledge.org>
     Message-ID:  <YfxGzCsd4AgoKTM/@wooledge.org>

   | This declares the variables at the wrong scope.

You are correct - I never normally use "declare" for anything, so
I had forgotten that it was essentially a clone of "local" (rather
than "local" being "declare -l" or something similar (I know
declare has a "-l" which is something entirely different, that's
not the point).

That has the cart before the horse. `local' is a synonym for `declare'.
`declare' has -- and has always had -- the ksh `typeset' semantics: if you
use it in a shell function, you get a local variable. `local' exists
because Posix 1003.2 draft 9 included it as a builtin, and we already had
the same functionality in `declare', so `local' came in as a synonym with
a check to make sure you were currently executing a shell function. Of
course, on the next draft, local variables were thrown out entirely.

Since this is bash local stuff, it would be useful to add an "uplevel"
option to declare, so that things like this can work.   It has -g already,
and while useful, it doesn't solve this problem.

Interesting idea. It would be a no-op (or an error) at the global scope,
naturally.


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

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