If I want to check for the existence of a single file, I can test for it using test -e filename
or [ -e filename ]
.
Supposing I have a glob
set -- glob*
if [ -f "$1" ]; then
echo "It matched"
fi
When there isn't a match for glob*
, then $1
will contain 'glob*'
. The test -f "$1"
won't be true because the glob*
file doesn't exist.
This works with sh and derivates: ksh and bash. It doesn't create any sub-shell. $(..)
and `...`
commands create a sub-shell; they fork a process, and therefore are slower than this solution.