Glob函数(c)和备份文件(file~)
我正在使用 glob 函数作为自动完成函数。我向您展示这个问题是因为它很难解释:
matched = ~/.tcsh
glob(matched, 0, NULL, &pglob);
glob 将所有匹配的文件放入一个 char ** 中,当我打印它时,我有:
case[0] = .tcshrc
case[1] =
我应该有 .tcshrc~
in case[1],但什么也没有=S,我见过这样的标志“GLOB_TILDE”“
glob(matched, GLOB_TILDE, NULL, &pglob);
但它不会改变任何东西!有人可以帮助我吗?
I'm using glob function for a autocompletion function. I'm showing you the problem because it's difficult to explain:
matched = ~/.tcsh
glob(matched, 0, NULL, &pglob);
glob put all matched files in a char ** and when I print it I have:
case[0] = .tcshrc
case[1] =
I should have .tcshrc~
in case[1], but nothing =S, I've seen a flag "GLOB_TILDE" like this "
glob(matched, GLOB_TILDE, NULL, &pglob);
But it doesn't change anything! Can someone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GLOB_TILDE 标志仅在 ~ 出现在 glob 开头时影响输出。请参阅此处:
http://www.gnu .org/s/libc/manual/html_node/More-Flags-for-Globbing.html
至于你的问题,在我看来你的匹配值是错误的。似乎您应该在其末尾添加一个
*
,这样它对于自动完成很有用,即:我对您之前的示例如何找到第一个示例感到有点困惑。这篇手册页文章的底部也有一些有趣的示例:
http:// www.opengroup.org/onlinepubs/000095399/functions/glob.html
The
GLOB_TILDE
flag only affects the output when the ~ appears at the beginning of the glob. See here:http://www.gnu.org/s/libc/manual/html_node/More-Flags-for-Globbing.html
As for your problem, it appears to me that your matched value is wrong. Seems like you should be sticking a
*
at the end of it for it to be useful for autocompletion, i.e.:I'm a little bit confused as how your previous example found even the first one. The bottom part of this man page article has some interesting examples too:
http://www.opengroup.org/onlinepubs/000095399/functions/glob.html