我有一个 shell 脚本来引导我的机器: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
我想将其提取到顶部的关联数组(字典/ 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
关于bash - 在 shell 脚本中设置键值对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30222651/