加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 为什么glob lstat匹配条目?

发布时间:2020-12-13 19:46:47 所属栏目:Linux 来源:网络整理
导读:在 this question中查看行为时,我惊讶地看到perl lstat() s每个路径都匹配一个glob模式: $mkdir dir$touch dir/{foo,bar,baz}.txt $strace -e trace=lstat perl -E 'say $^V; dir/b*' v5.10.1lstat("dir/baz.txt",{st_mode=S_IFREG|0664,st_size=0,...}) =
在 this question中查看行为时,我惊讶地看到perl lstat()s每个路径都匹配一个glob模式:
$mkdir dir
$touch dir/{foo,bar,baz}.txt  
$strace -e trace=lstat perl -E 'say $^V; <dir/b*>' 
v5.10.1
lstat("dir/baz.txt",{st_mode=S_IFREG|0664,st_size=0,...}) = 0
lstat("dir/bar.txt",...}) = 0

我在我的Linux系统上看到了与glob(模式)和< pattern>以及更高版本的perl相同的行为.

我的期望是,globbing只是opendir / readdir,并且它不需要检查它正在搜索的实际路径名.

这个lstat的目的是什么?它会影响glob()的返回吗?

解决方法

这个奇怪的行为已经是 noticed before on PerlMonks.事实证明,glob调用lstat来支持它的 GLOB_MARK标志,其结果是:

Each pathname that is a directory that matches the pattern has a slash appended.

要确定目录条目是否引用了子目录,您需要对其进行统计.即使没有给出标志,这显然已经完成.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读