GET_DIR=$ (find ${FIND_ROOT} -type -d 2>/dev/null | grep -Eiv ${EX_PATTERN| grep -Eio ${FIND_PATTERN})
但不知怎的,当我尝试打印结果时,它是空的。 但是当我在没有脚本的情况下使用我的grep时,我在命令行上得到了结果。
答案 0 :(得分:1)
您可以在|
中使用grep
或name
(不区分大小写)来避免管道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 (``\'').
答案 1 :(得分:0)
考虑使用xargs:
GET_DIR = $(找$ {FIND_ROOT} -type -d 2> / dev / null | xargs grep -Eiv $ {EX_PATTERN | grep -Eio $ {FIND_PATTERN})
答案 2 :(得分:-1)
GET_DIR=$(find ${FIND_ROOT} -type -d 2>/dev/null | grep -Eiv ${EX_PATTERN| grep -Eio ${FIND_PATTERN})