On Sat, Sep 26, 2026 at 2:13 PM <[email protected]> wrote:
>
> Which might explain why the initializing expression for an -A is treated as if
> -a was used. Bash is clearly parsing the -A, as it complains about conversion,
> but then ignores it when parsing the array expression, perhaps it's looking at
> the wrong variable?
>
> If that's the case, then it working for -a at global scope may be by accident.
When Chet shows up, he'll explain it better than me, but what bash is
doing is evaluating the assignment statements first, then trying to
apply the attributes you supplied as arguments to 'declare' after
that. The parser can't tell what those attributes are when it would
need to perform word expansions first, and then it may be passing the
declare command just the variable names from the assignment statements
along with any other arguments after the word expansions are
performed. You've found a particularly nasty side-effect of this,
though.
Whenever bash sees a compound assignment statement, it assumes an
indexed array unless it already knows that this thing has been
declared as an associative array. You don't need 'declare' at all, if
what you want is an indexed array at global scope with no other
attributes.
$ f () {
> arr=( zero one two )
> declare -p arr
> }
$ f
declare -a arr=([0]="zero" [1]="one" [2]="two")
$ declare -p arr
declare -a arr=([0]="zero" [1]="one" [2]="two")
I'm with kre here:
On Sat, Sep 26, 2026 at 1:51 PM Robert Elz <[email protected]> wrote:
>
> declaration utilities [...] need to be recognised just
> like reserved words (except a reserved word can't be quoted, or result from
> an expansion, whereas a declaration utility name can be ... it just isn't
> required to be recognised as a declaration utility if it is).
All the declaration utilities are defined in .def files under the
builtins directory in the bash source tree, just like any other
builtin command. (declare.def and setattr.def.)
Chet has said something to the effect of "no more reserved words that
take options" in the past. 'time' works that way, and maybe he's sick
of dealing with it. Trying to handle edge case after edge case with
declaration utilities working the way they do now seems like as much
of a pain, though.