Bash 用于将路径与可能包含通配符的模式匹配的代码
Bash code for matching paths with patterns that may include wildcards
我想知道 bash 如何检查文件路径和可能包含通配符“*”的模式之间的匹配。
我查看了 bash 开源并从 here 下载但无法弄清楚执行此处理的引擎在哪里..
也许它可以在其他地方找到?
例如,如果我有以下目录树:
~$ find 1
1
1/2
1/2/21
1/2/22
1/2/23
1/2/23/221
1/2/23/223
1/3
1/3/21
1/3/22
1/3/23
1/3/31
1/3/32
1/3/33
1/3/33/333
1/3/33/334
1/4
1/4/41
1/4/42
1/4/43
我想捕获属于“1”的成员且内容为“23”的所有文件。
~$ find 1/*/23
1/2/23
1/2/23/221
1/2/23/223
1/3/23
或找到1/2的所有成员:
~$ find 1/2
1/2
1/2/21
1/2/22
1/2/23
1/2/23/221
1/2/23/223
这称为 "globbing" 并由 GNU glibc 库函数处理:
https://www.gnu.org/software/libc/manual/html_node/Pattern-Matching.html#Pattern-Matching
另见 glob(3)
、glob(7)
和 fnmatch(3)
。
我想知道 bash 如何检查文件路径和可能包含通配符“*”的模式之间的匹配。
我查看了 bash 开源并从 here 下载但无法弄清楚执行此处理的引擎在哪里.. 也许它可以在其他地方找到?
例如,如果我有以下目录树:
~$ find 1
1
1/2
1/2/21
1/2/22
1/2/23
1/2/23/221
1/2/23/223
1/3
1/3/21
1/3/22
1/3/23
1/3/31
1/3/32
1/3/33
1/3/33/333
1/3/33/334
1/4
1/4/41
1/4/42
1/4/43
我想捕获属于“1”的成员且内容为“23”的所有文件。
~$ find 1/*/23
1/2/23
1/2/23/221
1/2/23/223
1/3/23
或找到1/2的所有成员:
~$ find 1/2
1/2
1/2/21
1/2/22
1/2/23
1/2/23/221
1/2/23/223
这称为 "globbing" 并由 GNU glibc 库函数处理:
https://www.gnu.org/software/libc/manual/html_node/Pattern-Matching.html#Pattern-Matching
另见 glob(3)
、glob(7)
和 fnmatch(3)
。