bug-bash
[Top][All Lists]
Advanced

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

Re: cannot declare local variables if they're readonly


From: Chet Ramey
Subject: Re: cannot declare local variables if they're readonly
Date: Thu, 23 Jul 2015 17:07:45 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

On 7/23/15 10:57 AM, isabella parakiss wrote:
> On 7/23/15, Greg Wooledge <wooledg@eeg.ccf.org> wrote:
>> People who use "readonly" are generally doing so in the context of a
>> "restricted shell" (yes, commence laughter) or other situation where
>> that specific variable is the key to unlocking something that the
>> administrator does not want the user to unlock.  The entity who used
>> "readonly" is presumed to want that variable to remain unchanged, forever.
> 
> On 7/23/15, Stephane Chazelas <stephane.chazelas@gmail.com> wrote:
>> 2015-07-23 01:12:01 +0200, isabella parakiss:
>> What that means is that with this kind of dynamic scoping,
>> "readonly" is not very helpful. I don't remember ever using it.
> 
> You guys are assuming that I am the one who uses readonly.
> I'm not, *bash* is.

This is an excellent time to point out that it's to everyone's advantage
to be as complete as possible when describing a problem on the list,
rather than revealing additional details one at a time.

There's no way anyone would have guessed that you were encountering this
with BASH_REMATCH; the most likely possibility was that you were trying to
override a variable you had declared readonly.

Yes, BASH_REMATCH is special.  It's not present by default, and it is
destroyed and reconstituted fresh every time you use the =~ operator to
[[, since it's only supposed to exist if something matched.  I suppose
there's no real reason to make it readonly other than that there's no real
reason to write to it, and =~ is the only thing that can modify it.
Removing the restriction on local copies of readonly variables wouldn't do
a thing to change the BASH_REMATCH semantics, though it would allow scripts
to unset it.  We would need a different discussion about how you'd like
BASH_REMATCH to work.

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



reply via email to

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