【问题标题】:Set key value pairs in a shell script在 shell 脚本中设置键值对
【发布时间】:2015-07-25 04:52:08
【问题描述】:

我有一个 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

我想将其提取到顶部的关联数组(字典/哈希图)中,并在一行代码中调用它。如何在 bash 4+ 中做到这一点?

【问题讨论】:

标签: bash shell scripting bash4


【解决方案1】:
# 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

【讨论】:

    猜你喜欢
    • 2015-05-22
    • 2014-06-15
    • 2014-07-13
    • 1970-01-01
    • 1970-01-01
    • 2019-03-16
    • 2016-05-29
    • 2013-05-08
    • 2016-05-07
    相关资源
    最近更新 更多