What am I doing wrong in the glob below? It looks like it should work according to my reading of the manual.

A '?' (not between brackets) matches any single character.

$ touch file.txt file.text
$ ls file.*
file.text  file.txt
$ ls file.te?xt
ls: cannot access 'file.te?xt': No such file or directory

$ bash --version
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)

1 Answer 1


The ? matches a single character (like . in a regular expression). You have no file matching the pattern file.te?xt so the pattern remains unexpanded.

You may have expected it to work as in a regular expression, where it means "zero or one of the previous expression". Unfortunately, there is no such wildcard in bash.

... unless you enable the extglob shell option:

shopt -s extglob

Then the pattern ?(list) would match zero or one of the patterns in list.

$ shopt -s extglob
$ ls file.t?(e)xt
file.text file.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .