我在这里找到了关联数组的实现, 并想了解代码的实际作用。这是我不理解的代码片段,希望能得到解释。'
put() {
if [ "$#" != 3 ]; then exit 1; fi
mapName=$1; key=$2; value=`echo $3 | sed -e "s/ /:SP:/g"` #dont understand
eval map="\"\$$mapName\"" **#dont understand**
map="`echo "$map" | sed -e "s/--$key=[^ ]*//g"` --$key=$value" #dont understand
eval $mapName="\"$map\"" #dont understand
}
get() {
mapName=$1; key=$2
map=${!mapName}
#dont understand
value="$(echo $map |sed -e "s/.*--${key}=\([^ ]*\).*/\1/" -e 's/:SP:/ /g' )"
}
getKeySet() {
if [ "$#" != 1 ];
then
exit 1;
fi
mapName=$1;
eval map="\"\$$mapName\""
keySet=`
echo $map |
sed -e "s/=[^ ]*//g" -e "s/\([ ]*\)--/\1/g" #dont understand
`
}
谢谢。