0

There are three files in a directory:

ab2 ab23 ab3

When I execute:

ls ab+(2|3)

It displays:

ab2 ab23 ab3

instead of ab2 and ab3 only.

Any ideas why it is like that? Is it a bug?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
szawel
  • 3
  • 1

1 Answers1

2

It's not a bug. +(pattern) matches one or more occurrences of the pattern. +(2|3) will match any combination and any number of 2's and 3's: 2, 3, 23, 32, 222, 333, 3223232323—any of those.

If you want strict alternation without repeats, change + to @:

ab@(2|3)

(Or just use ab[23]. That doesn't even require extglob.)

John Kugelman
  • 349,597
  • 67
  • 533
  • 578