On 9/28/26 4:46 PM, [email protected] wrote:
Next, it tries to gin up a shell variable for the expansion to apply to, to accommodate things like `-i', where the assignment will include things like arithmetic expansion. This is where it's important to detect `-g', since that determines the context where the variable is created. This is the evaluation order the `declare' builtin uses as well.In that case, is my conjecture that it's creating two variables from onecommand correct?
More or less, yes.
One local because it doesn't detect the -g in time, with a possibly misprocessed value because it doesn't detect an -A in time, and then a global with no value because it has no value left to give it by the time it actually detects the -g but tries to satisfy it either way?
Pretty much. Note that this all works as expected if the option string isn't quoted (though quoting the command name will mess things up as well).
declare -Ag assoc; assoc=(one two three four) which is how you should be writing these things in the first place.So if -r or other attributes are involved as well, are users supposed toalways turn one command into at least three?
If you're using -r, you have to do the obvious thing, since you have to assign the value before the variable is declared readonly.
Because there are gotchas there too, like having to repeat -g otherwise -r applies to a new blank local (which doesn't make any sense) instead of the existing global.
Why would it not? Unless you supply -g, `declare' in a function creates or
operates on local variables.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU [email protected] http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature
