2017-06-27 8 views
-1

環境を設定するためのスクリプトを書いています。新しい名前、電子メール、githubでgitを設定したいと考えています。以下のスクリプトのように、それぞれ-n -e -gオプションで渡している新しい値。user.nameに空白が含まれている場合、bashスクリプトでgitを設定してください。

残念ながら、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 

答えて

0

コマンドは括弧の中にカプセル化するための名前を必要とし、その解決策は次のようになります。

git config --global user.name "\"${OPTARG}\"" 
関連する問題