Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15928

Re: Inconsistent termination of function when 'local' tries to override read-only variable

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: Inconsistent termination of function when 'local' tries to override read-only variable
Date 2020-02-20 10:41 -0500
Message-ID <mailman.1259.1582213322.2412.bug-bash@gnu.org> (permalink)
References <CALaCa4znm+iQxG14TneqV3Hf3VNvHi-JWvsCmesB9ArBOUXSXg@mail.gmail.com> <d1d183d5-442b-48ca-f359-f51172278a67@case.edu>

Show all headers | View raw


On 2/19/20 2:36 PM, Arfrever Frehtes Taifersar Arahesis wrote:
> When scalar variable is read-only, then calling 'local' for this
> variable (regardless of presence of value in assignment) is non-fatal
> and subsequent commands in function are executed.

Correct. This is an implementation choice, and a controversial one, and
one that's been in place for about as long as bash has had local variables.
Bash creates the local variable with the inherited value, but doesn't allow
it to be changed. The rationale is that variables are readonly for a
reason, and you shouldn't be able to override readonly variables just by
calling a function. The local variable is created, so it's not a variable
assignment error.

There are advocates on both sides of this issue.

Here's the last time the issue came up:

https://lists.gnu.org/archive/html/bug-bash/2019-03/msg00150.html

It's come up multiple times over the years.

-- 
``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/

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Inconsistent termination of function when 'local' tries to override read-only variable Chet Ramey <chet.ramey@case.edu> - 2020-02-20 10:41 -0500

csiph-web