Q:

bash - Test if directory contains files ending on .suite

I'm currently writing a bash script for executing test suites. Besides passing the suites directly to this script, like
./bash-specs test.suite

it should also be able to execute all scripts in a given directory if no suite is passed to it, like so
./bash-specs # executes all tests in the directory, namely test.suite

This is implemented like this
(($# == 0)) && set -- *.suite

So, if no suite is passed, all the files ending on .suite are executed. This works fine but fails if the directory contains no such files.
That means I will also need a check to test if there actually are files with that ending.
How would I do this in bash?
I thought a test like 
[[ -f *.suite ]]

should work but it seems to fail when there are more than one file in the directory.

A:

The reason -f is failing is because -f only takes a single parameter. When you do [[ -f *.suite ]], it expands to:
[[ -f test.suite test2.suite test3.suite ]]

... which is not valid. 
Instead, do this:
shopt -s nullglob
FILES=`echo *.suite`
if [[ -z $FILES ]]; then 
    echo "No suites found"
    exit
fi

for i in $FILES; do
    # Run your test on file $i
done

nullglob is a shell option that makes wildcard patterns that aren't found expand to nothing, rather than expanding to the wildcard pattern itself. Once $FILES is set to either a list of files or nothing, we can use -z to test for emptiness, and display the appropriate error message.

