Prajwal Kumar
Prajwal Kumar

Reputation: 177

is there a way to check directory exists when similar filename exits?

I have a directory and a file with similar name. i.e. filename --> test_16.4 and directoryName --> test_16.43

if [ -d test_* ]; then
   echo " directory exists!!!"
else
   echo "directory doesn't exists!!!"
fi

This returns "directory doesn't exists!!!" as it checks the condition with filename. how can i make this work?

Upvotes: 1

Views: 32

Answers (1)

Cyrus
Cyrus

Reputation: 88644

Replace * with */ to get only directories.

For a quick test see output of:

echo test_*
echo test_*/

Upvotes: 2

Related Questions