For example:

    $ # a[0] is not set, but no error
    $ bash -uc 'a=() k=; declare -n r=a[k]; : "$r"; echo ok'
    ok
    $ # a[0] is not set, error
    $ bash -uc 'a=() k=; declare -n r=a[k]; : "${r}"; echo ok'
    bash: line 1: r: unbound variable

Can reproduce in bash 5.2.37, and devel branch.

Bash modifies the parameter_expand flags before calling
parameter_brace_expand_word() when using ${r} in this case,

subst.c:10072-10075 (devel 535a8150b65ee6888f54f602274dbbdcd77c788e)
    else
      {
        local_pflags |= PF_IGNUNBOUND|(pflags&(PF_NOSPLIT2|PF_ASSIGNRHS));
        tdesc = parameter_brace_expand_word (name, var_is_special, quoted, 
local_pflags, &es);

but it does not do that before calling it when using $r

subst.c:10973-10976 (devel 535a8150b65ee6888f54f602274dbbdcd77c788e)

    if (temp && *temp && valid_array_reference (temp, 0))
      {
        chk_atstar (temp, quoted, pflags, quoted_dollar_at_p, 
contains_dollar_at);
        tdesc = parameter_brace_expand_word (temp, SPECIAL_VAR (temp, 0), 
quoted, pflags, 0);

Maybe that is related to why this is happening.

o/
 emanuele6

Reply via email to