I'm trying to use lsearch
using glob test on sub-pattern, but it's not working:
set haystack {foo bar baz}
lsearch -inline -all $haystack baz; # finds baz
lsearch -inline -all $haystack *o; # finds foo
lsearch -inline -all $haystack {{baz,*o}}; # finds nothing
Sub-pattern works using the actual glob
command (the files being the haystack in that case), so it appears to be an issue with lsearch
.
glob {{b*,c*}}; # finds all files starting with either b or c
Is there a way to make it work?
No, the pattern that you use with lsearch
is not meant to be able to match what you are trying to make it match. The manual specifies that it uses:
the same rules as the string match command.
And there is no mention of the style { ... }
. If you look at the manual for glob however, you will see the { ... }
syntax mentioned:
{a,b,...}
Matches any of the sub-patterns a, b, etc.
You can however use -regexp
if you know the syntax. For your example, you could use:
set haystack {foo bar baz}
lsearch -inline -all -regexp $haystack {baz|.*o}; # finds foo baz