Reputation: 1
GET_DIR=$ (find ${FIND_ROOT} -type -d 2>/dev/null | grep -Eiv ${EX_PATTERN| grep -Eio ${FIND_PATTERN})
but somehow when I try to print the result, its empty. But when I am using my grep without a script I got results on the Command line.
Upvotes: 0
Views: 42
Reputation: 1
consider using xargs :
GET_DIR=$ (find ${FIND_ROOT} -type -d 2>/dev/null | xargs grep -Eiv ${EX_PATTERN| grep -Eio ${FIND_PATTERN})
Upvotes: 0
Reputation: 27005
You could avoid the pipe |
and grep
by using name
or iname
(case insensitive) within find
, for example:
find /tmp -type d -iname "*foo*"
This will find directories -type d
that match the pattern *foo*
ignoring case -iname
in /tmp
To save the output in a variable you could use:
FOO=$(find /tmp -type d -iname "*foo*")
From the find
man:
-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 (``\'').
Upvotes: 1