Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8784737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:10:36+00:00 2026-06-13T21:10:36+00:00

I have this small script that checks if a user name and email exist

  • 0

I have this small script that checks if a user name and email exist in git configuration, otherwise prompt the user to enter them:

GIT_USER_EXISTS=`git config --get-regexp 'name' | awk '{print $2}'`
GIT_EMAIl_EXISTS=`git config --get-regexp 'name' | awk '{print $2}'`
while [[ -z $GIT_USER_EXISTS || -z $GIT_EMAIl_EXISTS ]]; do
    echo "User name and Email are not set in git. Please enter them now..."
    echo "First and Last name:"
    read gitUser
    git config --global user.name "$gitUser"
    echo "Email:"
    read gitEmail
    git config --global user.email "$gitEmail"
done

It doesn’t work though;)

1st – it doesn’t even get into the loop in the first place.
My guess is that unlike grep, awk does insert some (hidden?) character to the variable.
2nd – I’m not sure if the script could recognize there are now values, since I declared the variables outside the loop. Am I wrong in this assumption?

EDIT:

I solved the 1st issue by using backticks instead of quotes for the variable names.
The second issue still stands – there must be a better using than declaring the variable twice?! something along the lines of do…while in shell?

EDIT #2:

This does the trick a little bit better, but has a rather long conditional statement. Could it possibly be any shorter?

while [[ -z $GIT_USER_EXISTS || -o $GIT_USER_EXISTS || -z $GIT_EMAIl_EXISTS || -o $GIT_EMAIl_EXISTS ]]; do
    echo "User name and Email are not set in git. Please enter them now..."
    echo "First and Last name:"
    read gitUser
    git config --global user.name "$gitUser"
    echo "Email:"
    read gitEmail
    git config --global user.email "$gitEmail"

    GIT_USER_EXISTS=`git config --get-regexp 'name' | awk '{print $2}'`
    GIT_EMAIl_EXISTS=`git config --get-regexp 'name' | awk '{print $2}'`
done

Actually it almost does the trick – it should be “if var is set and is empty or if var is not set”. But that would be much too long:)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:10:38+00:00Added an answer on June 13, 2026 at 9:10 pm

    Try doing this :

    GIT_USER_EXISTS="git config --get-regexp 'name' | awk '{print $2}'"
    GIT_EMAIl_EXISTS="git config --get-regexp 'name' | awk '{print $2}'"
    while [[ -z $GIT_USER_EXISTS || -z $GIT_EMAIl_EXISTS ]]; do
        echo "User name and Email are not set in git. Please enter them now..."
        echo "First and Last name:"
        read gitUser
        git config --global user.name "$gitUser"
        echo "Email:"
        read gitEmail
        git config --global user.email "$gitEmail"
        GIT_USER_EXISTS="git config --get-regexp 'name' | awk '{print $2}'"
        GIT_EMAIl_EXISTS="git config --get-regexp 'name' | awk '{print $2}'"
    done
    
    • if you test $GIT_USER_EXISTS or $GIT_EMAIl_EXISTS, you should declare it somewhere 😉
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this small PHP script that takes a POST variable and writes it
Currently I have this small script that makes it possible to check if a
I have a small script that checks a large list of domains for their
I have written a small jQuery script that checks the computed size of a
I have this small jquery script that does not work if I remove the
I have a small Inno script that checks the registry for you current .Net
I have this small class called City that simply holds some information about a
I have this small snippet to change a bit of html when a user
I have this small piece of code that basically takes a list and runs
I have a small script here that I need some help with: for song

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.