I was reading this answer on how to use negated glob patterns in Bash and I'm wondering why this glob pattern works:
$ ls !(*-renamed).jpg
IMG_1234.jpg
But this one does not:
$ ls *!(-renamed).jpg
IMG_1234.jpg IMG_1236-renamed.jpg
Is it because *
is too greedy? Or does it behave differently inside parentheses? I couldn't find an explanation in the Bash manual.
Because the *
matches IMG_1236-renamed
, !(-renamed)
matches an empty string, and .jpg
matches itself.