* is allowed in filenames, in particular *.txt is a valid name, so the whole idea is flawed. Additionally in your test there is no expansion at all. Normally unquoted $textfiles or unquoted asterisks in *'*'* trigger globbing, but inside [[ ]] the rules are different. Your [[ $textfiles == *'*'* ]] always returns success!