2

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

1 Answer 1

3

The command needs the name to be encapsulated into the brackets, so the solution would be:

git config --global user.name "\"${OPTARG}\""
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.