[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: It is possible to remove the readonly attribute from {BASH, SHELL}OP
From: |
Koichi Murase |
Subject: |
Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS |
Date: |
Tue, 20 Feb 2024 18:57:08 +0900 |
2024年2月20日(火) 18:12 Martin D Kealey <martin@kurahaupo.gen.nz>:
> So yes please, I'd like "local" to push a new variable definition that
> inherits nothing from any outer one: not name-ref, not read-only, not array
> (of any kind), not assignment modifiers (integer, upper-case, lower-case),
> and above all, not any previous values.
In my understanding, Bash behaves as you hope from the beginning
except for the global readonly variables (2.04+) and the export
attribute. I also checked the behavior of old versions now, but Bash
seems to behave in that way at least in Bash 2.0. If I'd raise some
exceptions, I thought in the past there was a bug that some array
attribute or behavior were inherited to a local variable (but don't
remember exactly), but that's just a bug found in a very limited
situation. Also, the recently added option `shopt -s localvar_inherit'
turns on the behavior you hate, but it's not enabled by default.
> Ideally each function invocation would have its own variable namespace,
> only using the global namespace as a fall-back,
That breaks so many existing scripts.
> Maybe this would be twisting 'local' too much, and it warrants creating a
> new keyword such as 'var'?
Perl's `local' is dynamic scoping, but Perl later added `my' for the
lexical scoping. Eric Blake suggested `local -s' [1]. Alex xmb
suggested `local -L' [2].
[1] https://lists.gnu.org/archive/html/bug-bash/2010-11/msg00036.html
[2] https://lists.gnu.org/archive/html/help-bash/2021-05/msg00094.html
--
Koichi
- Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS, Grisha Levit, 2024/02/13
- Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS, Chet Ramey, 2024/02/16
- Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS, Grisha Levit, 2024/02/16
- Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS, Martin D Kealey, 2024/02/20
- Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS,
Koichi Murase <=
- Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS, Chet Ramey, 2024/02/20
- Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS, Martin D Kealey, 2024/02/22
- Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS, Chet Ramey, 2024/02/23
- Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS, Robert Elz, 2024/02/23
- Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS, Chet Ramey, 2024/02/23
- Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS, Robert Elz, 2024/02/23
- Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS, Martin Kealey, 2024/02/25