bash - 在 shell 脚本中设置键值对

标签 bash shell scripting bash4

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

相关文章:

bash - 如何创建 100 个文件,每个文件中有 1 个随机数,并根据数字授予它们权限

linux - 如何使用 bashrc 函数更改到文件目标目录?

javascript - 动态加载 Javascript 对象的性能问题

linux - 用于检查远程服务器进程的 Perl 脚本

linux - 使用多个 Linux 隧道运行 Windows 脚本

Linux分组、求和和计数

从终端在 mac 中找不到 mysql 命令

ruby - 从 shell 中调用 ruby

linux - 在不采购 .bashrc 的情况下打开 gnome-terminal

java - 计算机代数系统的 GUI