This question already has an answer here:
I want to check whether or not the hidden .git
folder exists. First thought was to use:
if [ -d "~/.git" ]; then
echo "Do stuff"
fi
But the -d
apparently does not look for hidden folders.
This question already has an answer here:
I want to check whether or not the hidden .git
folder exists. First thought was to use:
if [ -d "~/.git" ]; then
echo "Do stuff"
fi
But the -d
apparently does not look for hidden folders.
The problem has to do with the tilde being within double quotes.
To get it expanded, you need to put the tilde outside the quotes:
Or, alternatively, as commented below by hek2mgl, use
$HOME
instead of~
:From POSIX in Tilde expansion:
From POSIX in Double Quotes:
You can find further explanations in Why doesn't the tilde (~) expand inside double quotes? from the Unix & Linux Stack.