The properA way, in bash: if you want to know if there's some files matching the pattern *.txt, then consider:
(
shopt -s nullglob
compgen -W *.txt &>/dev/null
case $? in
0) echo 'one match' ;;
1) echo 'more than one match' ;;
3) echo 'no match at all' ;;
esac
)
The subshell ( ) is here only to reset shopt as default settings. Can use
shopt -u nullglob
too.
Note
It's different than compgen -G, because here we can discriminates more cases