Test whether a glob has any matches in bash
Posted
by Ken Bloom
on Stack Overflow
See other posts from Stack Overflow
or by Ken Bloom
Published on 2010-05-30T03:22:46Z
Indexed on
2010/05/30
3:32 UTC
Read the original article
Hit count: 308
If I want to check for the existance of a single file, I can test for it using test -e filename
or [ -e filename ]
.
Supposing I have a glob and I want to know whether any files exist whose names match the glob. The glob can match 0 files (in which case I need to do nothing), or it can match 1 or more files (in which case I need to do something). How can I test whether a glob has any matches.?
(test -f glob*
fails if the glob matches more than one file.)
© Stack Overflow or respective owner