将关联数组作为参数传递给函数以避免重复必须迭代众多关联数组的最佳方法是什么?这样我就可以为函数提供我选择的任何数组来打印。这是我所拥有的:
# Snippet
declare -A weapons=(
['Straight Sword']=75
['Tainted Dagger']=54
['Imperial Sword']=90
['Edged Shuriken']=25
)
print_weapons() {
for i in "${!weapons[@]}"; do
printf "%s\t%d\n" "$i" "${weapons[$i]}"
done
}
print_weapons