在 shell 脚本中设置键值对

Set key value pairs in a shell script

我有一个 shell 脚本到 bootstrap 我的机器:https://github.com/pathikrit/mac-setup-script/blob/master/setup.sh

我有这几行代码可以设置 git:

git config --global rerere.enabled true
git config --global branch.autosetuprebase always
git config --global credential.helper osxkeychain

我想将其提取到顶部的关联数组 (a dictionary/hashmap) 并在一行代码中调用它。我怎样才能在 bash 4+ 中做到这一点?

# Create the associative array
declare -A opts
opts[rerere.enabled]=true
opts[branch.autosetuprebase]=always
opts[credential.helper]=osxkeychain

# Use the associative array
for k in "${!opts[@]}"
do
    git config --global "$k" "${opts[$k]}"
done