On Mon, Mar 21, 2022 at 02:47:12PM -0400, Lawrence Velázquez wrote: > On Mon, Mar 21, 2022, at 8:50 AM, Alexey via Bug reports for the GNU Bourne > Again SHell wrote: > > I can add one more example, which change array size while it's not > > expected behavior: > > x=("/"); y=("${x[@]%/}"); echo "x size: ${#x[@]}, y size: ${#y[@]}" > > This discrepancy seems to have been introduced some ways back. > > <larryv> 3# echo "$BASH_VERSION"; x=("/"); y=("${x[@]%/}"); echo "x ${#x[@]}, > y ${#y[@]}" > <shbot> 3.2.48(1)-release > <shbot> x 1, y 1 > <larryv> 42# echo "$BASH_VERSION"; x=("/"); y=("${x[@]%/}"); echo "x > ${#x[@]}, y ${#y[@]}" > <shbot> 4.2.45(1)-release > <shbot> x 1, y 0
Good point. The behavior definitely changed between 4.1 and 4.2. unicorn:~$ bash-3.2 -c 'x=("/"); for i in "${x[@]%/}"; do echo "i is [$i]"; done' i is [] unicorn:~$ bash-4.0 -c 'x=("/"); for i in "${x[@]%/}"; do echo "i is [$i]"; done' i is [] unicorn:~$ bash-4.1 -c 'x=("/"); for i in "${x[@]%/}"; do echo "i is [$i]"; done' i is [] unicorn:~$ bash-4.2 -c 'x=("/"); for i in "${x[@]%/}"; do echo "i is [$i]"; done' unicorn:~$