In a bash script, I need to prompt the user for an email address, but only if git user.email is not set or there is no ssh key. I have very little experience with bash, so I've been coming to stackoverflow again and again for this project.
Based on this stackoverflow answer, I came up with this:
if [[ ! -f "$HOME/.ssh/id_rsa" ]]; then
echo "No File Found"
else
echo "File Found"
fi
This has the expected behavior: If id_rsa
exists, it says File Found; If I remove id_rsa
, it says No File Found.
However, I cannot get this to work as part of a longer expression. Here's what I have so far:
md_email=$4
... more code ...
if [[ "$md_email" = "" && "`git config --get user.email`" = "" || ! -f "$HOME/.ssh/id_rsa" ]]; then
echo "No File Found"
else
echo "File Found"
fi
This will always print No File Found. I've tried various combinations of brackets, double brackets, and parentheses, in the hope of isolating the second and third expressions from the first as well as isolating the third from the rest in a way that might make it work. All to no avail. What am I missing?
At request of @codeforester:
ls -l $HOME/.ssh/id_rsa
-rw------- 1 menasheh menasheh 3243 Feb 13 22:52 /home/menasheh/.ssh/id_rsa`