[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How changes in an associate array affect the iteration of its keys?
From: |
Peng Yu |
Subject: |
How changes in an associate array affect the iteration of its keys? |
Date: |
Mon, 29 Mar 2021 19:01:07 -0500 |
Hi,
declare -A x=(
[a]=
[b]=
[c]=
)
for k in "${!x[@]}"; do
echo "==> $k <=="
unset x[$k]
declare -p x
if ((++i==1)); then
x[x]=
fi
done
# output
==> c <==
declare -A x=([b]="" [a]="" )
==> b <==
declare -A x=([x]="" [a]="" )
==> a <==
declare -A x=([x]="" )
I have the above bash code. In this example, the changes to the
associative array x within the loop does not affect the enumeration of
the keys of x?
Is it always the case?
--
Regards,
Peng
- How changes in an associate array affect the iteration of its keys?,
Peng Yu <=