I am writing a script to set-up the environment and I want to be possible to configure git with the new name, email and github acc. The new values I am passing with options -n -e -g respectively as in the script below.
Unfortunately, if the user.name contains spaces the $git_name variable is referring only to the first part of it. Is there a way to do this correctly and clean?
#!/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