Tente isto:
shopt -s nullglob
files=(*.txt *.pdf *.doc *.docx)
if [[ ${#files} -eq 0 ]]; then echo "nothing found"; fi
ou
shopt -s nullglob extglob
files=(*.+(txt|pdf|doc|docx))
if [[ ${#files} -eq 0 ]]; then echo "nothing found"; fi
Se você precisar de arquivos de todos os subdiretórios também:
shopt -s nullglob extglob globstar
files=(**/*.+(txt|pdf|doc|docx))
if [[ ${#files} -eq 0 ]]; then echo "nothing found"; fi
De 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.
?(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