why is bash pattern match for ?(*[[:class:]])foobar slow?
I have a text file foobar.txt which is around 10KB, not that long. Yet the
following match search command takes about 10 seconds on a
high-performance Linux machine.
bash>shopt -s extglob
bash>[[ `cat foobar.txt` == ?(*[[:print:]])foobar ]]
There is no match: all the characters in foobar.txt are printable but
there is no string "foobar".
The search should try to match two alternatives, each of them will not match:
"foobar"
that's instantenous
*[[:print:]]foobar
- which should go like this:
should scan the file character by character in one pass, each time, check
if the next characters are
[[:print:]]foobar
this should also be fast, no way should take a milisecond per character.
In fact, if I drop ?, that is, do
bash>[[ `cat foobar.txt` == *[[:print:]]foobar ]]
this is instantaneous. But this is simply the second alternative above,
without the first.
So why is this so long??
Thank you
No comments:
Post a Comment