I fiddled around with extended globbing in bash, but there is some oddity with the inverse matcher !(PATTERN). Consider the following example
$ touch ab ba
$ shopt -s extglob
$ echo *a*
ab ba
$ echo !(a)*a*
ab ba
$ echo *a*!(a)
ab
Now it looks like !() matches the empty string, but why doesn't *a*!(a) match ba?
I assumed that in the second example ab is matched like so
!(a) -> ""
* -> ""
a -> "a"
* -> "b"
which in turn would suggest a match of ba in the third case like so
* -> "b"
a -> "a"
* -> ""
!(a) -> ""
but looks like this doesn't work.
Even considering greediness, that doesn't make any sense to me. What am I missing?
edit:
I'm on GNU bash, Version 4.1.7(2)-release (i386-apple-darwin10.4.0)
GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)