I wish to perform an action if a file does not exists in bash with the following command:
if [ ! -a $HOME/.some_directory ] ; then
# do something
fi
However the #do something
part is always executed regardless of the existence of $HOME/.some_directory
.
I've created a small test where I have tried all cases:
- nonexistent directory check
- negated nonexistent directory check
- existent directory check
- negated existent directory check ( this is the only one returning an "invalid" result) - or I am doing something wrong
Here is a screenshot of the result:
Notes:
~/bin
is present while~/bina
is not- I am using bash version:
4.3.18
- I've used
$HOME
instead of~
because of this SO question - I've taken the file existence check suggestions from this SO question and this reference