我正在写一个脚本来设置环境,我想可以配置git与新的名称,电子邮件和github访问。在下面的脚本中,我分别使用options -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发布于 2017-06-28 00:48:45
该命令需要将名称封装到括号中,因此解决方案为:
git config --global user.name "\"${OPTARG}\""https://stackoverflow.com/questions/44785639
复制相似问题