I want to check if some directories with common prefix exist under current directory with bash, say, I have dictories like:
dirct_1
dirct_2
dirct_3
...
in the current directory. I did:
if [ -d dirct* ]
then
echo " directories exist "
else
echo " directories not exist "
fi
However, it returns me:
[: too many arguments
Then I tried to count the lines of ls output with:
DIR=$(ls ./dirct*> /dev/null | wc -l)
if [ "$DIR" != "0" ]
...
else
...
However, as I do not have the /dev/null in my ubuntu 10.04 system. I can not send the line
ls: cannot access ./dirct*: No such file or directory
to the null. So if there is no dirct* directory existing, there will be a trouble.
So, How could I avoid these problem?
Many Thanks!
Cristalp