linux - 我正在尝试 grep 文件夹并将结果变量作为进一步需要
问题描述
GET_DIR=$ (find ${FIND_ROOT} -type -d 2>/dev/null | grep -Eiv ${EX_PATTERN| grep -Eio ${FIND_PATTERN})
但不知何故,当我尝试打印结果时,它是空的。但是当我在没有脚本的情况下使用我的 grep 时,我在命令行上得到了结果。
解决方案
您可以避免使用管道|
并在 内grep
使用name
or iname
(不区分大小写)find
,例如:
find /tmp -type d -iname "*foo*"
这将找到-type d
匹配模式*foo*
忽略大小写-iname
的目录/tmp
要将输出保存在变量中,您可以使用:
FOO=$(find /tmp -type d -iname "*foo*")
来自find
男人:
-name pattern
True if the last component of the pathname being examined matches pattern. Special shell pattern matching
characters (``['', ``]'', ``*'', and ``?'') may be used as part of pattern. These characters may be matched
explicitly by escaping them with a backslash (``\'').
推荐阅读
- javascript - 如何编写函数结果
- c++ - 当一个变量比c ++中的另一个变量持有更少的位/字节时有什么区别
- android - 从graphql客户端连接到全局服务器的问题本机反应
- python - Python:即使它肯定存在,也不会在列表中找到字符串
- python - 当我使用 YOLACT 运行 train.py 时,我收到错误 KeyError: 0
- python - 按值对大字典进行排序
- ios - ARSCNView 中 arView.scene.addAnchor() 的等价物是什么?
- html - 如何使用多个音频标签
- next.js - 如何在 nextjs 中检查每个请求的 cookie?
- php - 无法理解 php 中对象和数组的逻辑