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

unix – 为什么zsh globbing不能使用find命令?

发布时间:2020-12-16 01:13:51 所属栏目:安全 来源:网络整理
导读:我一直在使用zsh globbing来执行以下命令: vim **/filename vim *.html.erb 等等,但当我输入类似的东西时: find . -name *mobile* 我收到了回复: zsh: no matches found: *mobile* 为什么? find . -name *mobile* # does not work VS find . -name '*mob
我一直在使用zsh globbing来执行以下命令:
vim **/filename
 vim *.html.erb

等等,但当我输入类似的东西时:

find . -name *mobile*

我收到了回复:

zsh: no matches found: *mobile*

为什么?

find . -name *mobile* # does not work

VS

find . -name '*mobile*' # works

差异是由于shell在解析一行时所采取的步骤.通常,shell会在运行命令之前展开它找到的任何通配符.但是,单引号将参数标记为文字,这意味着在运行命令之前,shell不会对该参数执行通配符扩展.

为了演示差异,假设您位于包含以下文件的目录中:

$tree
./
mobile.1
dir/
    mobile.2

在运行之前,zsh会将第一个表单扩展为以下表单:

find . -name mobile.1

这意味着find只会查找名为literally mobile的文件

第二个表格将按如下方式运行:

find . -name *mobile*

这意味着find将查找包含字符串“mobile”的任何文件名.

这里要注意的重要一点是,zsh和find都支持相同的通配符语法,但是你希望find在这种情况下处理通配符,而不是zsh.

(编辑:李大同)

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

    推荐文章
      热点阅读