What Does -D Value in an If Expression in Shell?
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 4 2 Answers You Can Use It...
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