【发布时间】:2017-11-30 19:46:07
【问题描述】:
我正在编写一个脚本来设置环境,我希望能够使用新名称、电子邮件和 github acc 配置 git。我通过选项 -n -e -g 分别传递的新值如下面的脚本所示。
不幸的是,如果 user.name 包含空格,则$git_name 变量仅引用它的第一部分。有没有办法正确和干净地做到这一点?
#!/bin/bash
git_github=`git config --global --get-all user.github`
git_email=`git config --global --get-all user.email`
git_name="$(git config --global --get-all user.name)"
echo "Before:" $git_github $git_email $git_name
while getopts :g:e:n: option
do
case "${option}"
in
g) git config --global user.github ${OPTARG};;
e) git config --global user.email ${OPTARG};;
n) git config --global user.name ${OPTARG};;
esac
done
git_github=`git config --get user.github`
git_email=`git config --get user.email`
git_name=`git config --get-all user.name`
echo "After:" $git_github $git_email $git_name
【问题讨论】:
标签: git bash shell environment-variables sh