Check folder existence using wildcard

Hi

I would like to know how I can check whether there is one or more folders in the current directory which begins with e.g. 2011-11.

Initially I figured that this could easily be done simply by:

if [ -d 2011-11* ]; then ...

However if there is more than one folder which begins with 2011-11 then it will not work as I intended.

Can anyone help me solve this problem?

Kind regards
Anders

FOUND=

for DIR in 2011-11*
do
        if [ -d "$DIR" ]
        then
                FOUND="$DIR"
                break
        fi
done

if [ -d "$FOUND"] 
then
        echo "Found folder $FOUND"
else
        echo "No folder found matching 2011-11*"
fi
1 Like