子模式 globbing 不适用于 lsearch
Sub-pattern globbing not working for lsearch
我正在尝试 lsearch
在子模式上使用 glob 测试,但它不起作用:
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
子模式使用实际的 glob
命令工作(在那种情况下文件是大海捞针),所以它似乎是 lsearch
.
的问题
glob {{b*,c*}}; # finds all files starting with either b or c
有没有办法让它起作用?
不,您与 lsearch
一起使用的模式并不意味着能够匹配您试图使其匹配的内容。 manual 指定它使用:
the same rules as the string match command.
并且没有提及样式{ ... }
。但是,如果您查看 manual for glob,您会看到提到的 { ... }
语法:
{a,b,...}
Matches any of the sub-patterns a, b, etc.
不过,如果您知道语法,则可以使用 -regexp
。对于您的示例,您可以使用:
set haystack {foo bar baz}
lsearch -inline -all -regexp $haystack {baz|.*o}; # finds foo baz
我正在尝试 lsearch
在子模式上使用 glob 测试,但它不起作用:
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
子模式使用实际的 glob
命令工作(在那种情况下文件是大海捞针),所以它似乎是 lsearch
.
glob {{b*,c*}}; # finds all files starting with either b or c
有没有办法让它起作用?
不,您与 lsearch
一起使用的模式并不意味着能够匹配您试图使其匹配的内容。 manual 指定它使用:
the same rules as the string match command.
并且没有提及样式{ ... }
。但是,如果您查看 manual for glob,您会看到提到的 { ... }
语法:
{a,b,...}
Matches any of the sub-patterns a, b, etc.
不过,如果您知道语法,则可以使用 -regexp
。对于您的示例,您可以使用:
set haystack {foo bar baz}
lsearch -inline -all -regexp $haystack {baz|.*o}; # finds foo baz