Re: integer variable that unsets itself causes segfault
From:
Chet Ramey
Subject:
Re: integer variable that unsets itself causes segfault
Date:
Thu, 4 Sep 2025 09:56:52 -0400
User-agent:
Mozilla Thunderbird
On 9/3/25 9:47 PM, Zachary Santer wrote:
On Wed, Sep 3, 2025 at 4:05 PM Chet Ramey <chet.ramey@case.edu> wrote:
So the question is now whether to disallow `declare -in foo' (or
`declare -in foo=bar') and make it a usage error, print a warning that
it will be ineffective, or simply let it be ineffective, as it is now.
You already implemented this:
$ declare -in name=x[0]
bash: declare: x[0]: expands to invalid variable name for name reference
The question is to whether to disallow it immediately or wait until there
is an assignment.
The case without =value in the argument to declare is quite broken:
Well, it's inconsistent, which is what we're talking about here. Consider
declare -a a=('4')
declare -n b='a[0]'
declare -ni b
declare -p a b
b=4+3
This is a straightforward application of the nameref rules. The problem
is that the arithmetic expansion is not helpful, since you can't use
namerefs to set the positional parameters. We can make that clearer.
--
``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/