[英]I'm trying to grep folders and make a variable of the result for further need
GET_DIR=$ (find ${FIND_ROOT} -type -d 2>/dev/null | grep -Eiv ${EX_PATTERN| grep -Eio ${FIND_PATTERN})
但是以某種方式嘗試打印結果時,結果為空。 但是,當我在不使用腳本的情況下使用grep時,在命令行上會得到結果。
您可避免管道|
和grep
通過在find
使用name
或iname
(不區分大小寫)進行,例如:
find /tmp -type d -iname "*foo*"
這將找到與模式*foo*
匹配的目錄-type d
,而忽略/tmp
case -iname
要將輸出保存到變量中,可以使用:
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 (``\'').
考慮使用xargs:
GET_DIR = $(查找$ {FIND_ROOT} -type -d 2> / dev / null | xargs grep -Eiv $ {EX_PATTERN | grep -Eio $ {FIND_PATTERN})
GET_DIR=$(find ${FIND_ROOT} -type -d 2>/dev/null | grep -Eiv ${EX_PATTERN| grep -Eio ${FIND_PATTERN})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.