[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Inconsistent termination of function when 'local' tries to override
Re: Inconsistent termination of function when 'local' tries to override read-only variable
Thu, 20 Feb 2020 10:41:55 -0500
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.5.0
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
There are advocates on both sides of this issue.
Here's the last time the issue came up:
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 address@hidden http://tiswww.cwru.edu/~chet/