See also this thread: http://stackoverflow.com/questions/12596468/
It looks like there is some bug in the pattern matcher
$ shopt -s extglob
$ touch a ab ba
$ echo a*!(x)
Expected result:
a ab
Experienced result:
ab
This is particularly weird since other combinations work fine:
$ echo *!(x)a
a ba
$ echo !(x)*a
a ba
$ echo a!(x)*
a ab
I assume it has something to do with the EXTMATCH implementation in
lib/glob/sm_loop.c, but I haven't been able to figure out what exactly the
problem is. Not sure if I fully understand the idea behind the for-loops there.