On 5/14/25 8:26 PM, Emanuele Torre wrote:
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

Thanks for the report. These should both result in an unbound variable
error unless the subscript is `@' or `*'.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to