Try this:
shopt -s nullglob
files=(*.txt *.pdf *.doc *.docx)
if [[ ${#files} -eq 0 ]]; then echo "nothing found"; fi
or
shopt -s nullglob extglob
files=(*.+(txt|pdf|doc|docx))
if [[ ${#files} -eq 0 ]]; then echo "nothing found"; fi
If you need files from all subdirectories too:
shopt -s nullglob extglob globstar
files=(**/*.+(txt|pdf|doc|docx))
if [[ ${#files} -eq 0 ]]; then echo "nothing found"; fi
From man bash
:
nullglob
: If set, bash allows patterns which match no files to expand to a null string, rather than themselves.
extglob
: If set, the extended pattern matching features are enabled. See below.
globstar
: If set, the pattern ** used in a pathname expansion context will match all files and zero or more directories and subdirectories.
Extended globbing:
?(pattern-list)
: Matches zero or one occurrence of the given patterns
*(pattern-list)
: Matches zero or more occurrences of the given patterns
+(pattern-list)
: Matches one or more occurrences of the given patterns
@(pattern-list)
: Matches one of the given patterns
!(pattern-list)
: Matches anything except one of the given patterns