What command checks if a directory exists in another path using shell script?
I searched about this, but all I could find was checking if a directory exists in "current" directory.
if [ -d "$DIRECTORY" ]; then
# found "any" directory
fi
This doesn't satisfy when I want to know if "any" directory exist inside of another directory.
if [ -d "./PATH/$DIRECTORY" ]; then
# found "any" directory in subdirectory
fi
Apparently this did not work. This still checks from current working directory, not the path I have given.
Any suggestions?
I would like to use this in if condition, so answering with keeping that form would be helpful.
EDIT
In shell script I added as following:
#!/bin/bash
ls -ld ./smth/world/
echo DIRECTORY=$DIRECTORY
if [ -d "./smth/$DIRECTORY/" ]; then
echo hi
else
echo nope
fi
in the current directory, I have a directory called "smth". Inside that "smth" I created a dummy directory "world"
EDIT #2
After I added the dot in front of path, I get the following:
drwxrwxr-x 2 (myname) (myname) 4096 Sep 5 14:39 ./smth/world/
DIRECTORY=
found
BUT after I delete the world directory inside of smth directory, still get "found".
DIRECTORYcontains the word world. The expressions ` [ -d "/smth/$DIRECTORY" ]` or alternatively[[ -d /smth/$DIRECTORY ]]both test, whether the directory/smth/world(absolute path) exists. If your test doesn't show the desired result, I suggest that you - just for testing purpose do als -ld /smth/worldand aecho DIRECTORY=$DIRECTORYright before theifstatement. If your goal is to test something different, please rephrase your question.