0

I am trying to use extglob, however, after the man pages I'm confused about how *(patternList) operates. Assume I use the following commands:

touch A  Ax  Axxx  Axxxx  Ay  X  X.bak  x  xx  xxxx 
ls A*(xx)

Why does this only print A Axxxx. Doesn't Axxx also contain exactly one occurrence of xx? Furthermore, why is Ay not printed since it has 0 occurences of xx?

3

The pattern must be a match for the whole name, not just a prefix of the name.

Ay does not match A*(xx) because it does not consist of A followed by any number of xx. The y is not matched by the pattern. Ay does match A*(xx)y and A*(xx)? and A*(xx)*.

Similarly, Axxx does not match A*(xx) because it does not consist of A followed by any number of xx. Axxx does match A*(x) (A followed by three times x), A*(xx)x (A followed by one time xx followed by x), A*(xx)?, A*(xx)*, etc.

0
2

Doesn't Axxx also contain exactly one occurrence of xx?

It does - but it also has an additional x that is not matched by the pattern A*(xx). It would be matched by A*(xx)? for example.

Furthermore, why is Ay not printed since it has 0 occurences of xx?

Again, because there is nothing in the pattern to match the trailing y.

I guess what it comes down to is that globs are whole string matches.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.