I am trying to understand a part of search function written in a piece of code below is the expression mentioned.
if [ -d $1]
then
<action block>
2 Answers
You can use it to determine if a directory exist like
if [ -d "$DIR" ]; then
# code
fi
The -d is used to find if a given directory is exists or not. If it is exists the condition will be true. if not the condition will be false.
Where as -f is used to find if a given file is exists or not. If it is exists the condition will be true. if not the condition will be false
if [ -d "$dirname" ]
then
echo "directory is present"
else
echo "directory is not present"
fi