On 7/22/14, 1:24 PM, Corentin Peuvrel wrote:
> Hello,
>
> I think I found a bug in bash-4.3.
>
> An example should be self-explanatory :
>
> bash-4.2 :
> $ arr=( idx1 idx2 )
> $ i=arr[1]
> $ echo ${!i}
> idx2
> $ echo ${!i/x/X}
> idX2
>
> bash-4.3 :
> $ arr=( idx1 idx2 )
> $ i=arr[1]
> $ echo ${!i}
> idx2
> $ echo ${!i/x/X}
> idX1
>
> If we use pattern substitution (or removing prefix/suffix pattern, ...)
> with an expansion of an array name which contain a non zero index, it will
> still use the index 0.
Thanks for the report. This is the result of the variable indirection
discarding the correct index. The attached patch should fix it.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU [email protected] http://cnswww.cns.cwru.edu/~chet/
*** ../bash-4.3-patched/subst.c 2014-06-03 09:32:44.000000000 -0400
--- subst.c 2014-07-23 09:58:19.000000000 -0400
***************
*** 7369,7373 ****
if (want_indir)
! tdesc = parameter_brace_expand_indir (name + 1, var_is_special, quoted, quoted_dollar_atp, contains_dollar_at);
else
tdesc = parameter_brace_expand_word (name, var_is_special, quoted, PF_IGNUNBOUND|(pflags&(PF_NOSPLIT2|PF_ASSIGNRHS)), &ind);
--- 7445,7455 ----
if (want_indir)
! {
! tdesc = parameter_brace_expand_indir (name + 1, var_is_special, quoted, quoted_dollar_atp, contains_dollar_at);
! /* Turn off the W_ARRAYIND flag because there is no way for this function
! to return the index we're supposed to be using. */
! if (tdesc && tdesc->flags)
! tdesc->flags &= ~W_ARRAYIND;
! }
else
tdesc = parameter_brace_expand_word (name, var_is_special, quoted, PF_IGNUNBOUND|(pflags&(PF_NOSPLIT2|PF_ASSIGNRHS)), &ind);