Why does the glob `*[!t]*` return files whose names contain `t`s?

Viewed 57

I have really no idea after reading glob (programming) of the results printed by following command in shell, I'm using (bash) as my shell. Given this directory hierarchy:

/sub2
    s.py
    t2.txt
    nametoname.txt
    bees.txt
    /sub22

$ echo *[!t]*
bees.txt nametname.txt s.py sub22 t2.txt 

In my understanding the arguments to echo will be expanded to match any filenames that don't contain the letter t, but the result was quite the opposite, why?

This command outputs all filenames that contain the letter t:

$ echo *[t]*
nametname.txt t2.txt

In the previous command I just negated [t] to [!t], then in my expectation it should do the opposite of the second command.

3 Answers
Related