LS,
Unless I have not read the manual properly, bash has an issue with the
key part used to address a value within associated arrays. I tried this
in the bash 4.4.x and 5.x series of bash under OpenSUSE 15.2 and TW.
Addressing associative arrays with an array statement - like echo
${k["${a[x]}"] does not work.
The resulting data from ${a[x]} is technical a string, but is not
treated as such when using an associative array. Instead, one should
first copy the contents of the indexed ${a[x]} array to an ordinary
shell variable and then use this variable as the key in an associative
array.
Next a script to clarify my point:
! /bin/bash
declare -A k
declare -a a
declare -i i=2
declare sString="devel packager's guide"
k["$sString"]=$i
a[$i]=$sString
echo ${k["$sString"]}
echo ${a[$i]}
unset -v 'k["${a[$i]}"]' # does not work
echo ${k["$sString"]}
sTemp=${a[$i]}
unset -v 'k["$sTemp"]' # does work
echo ${k["$sString"]}
unset -v a[$i]
Is this an intended feature or a possible bug?
--- Frans.
--
A: Yes, just like that A: Ja, net zo
Q: Oh, Just like reading a book backwards Q: Oh, net als een boek
achterstevoren lezen
A: Because it upsets the natural flow of a story A: Omdat het de natuurlijke
gang uit het verhaal haalt
Q: Why is top-posting annoying? Q: Waarom is Top-posting zo
irritant?