lundi 13 février 2017

Bash - Check if a file exists as part of a longer expression

Vote count: 0

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=
echo `git config --get user.email`
if [[ "$md_email" = "" && "`git config --get user.email`" = "" || ! -f "$HOME/.ssh/id_rsa" ]]; then
    echo "No File Found"
else
    echo "File Found"
fi

asked 53 secs ago

Let's block ads! (Why?)



Bash - Check if a file exists as part of a longer expression

Aucun commentaire:

Enregistrer un commentaire