On Tue, Aug 03, 2021 at 10:59:38AM +0000, hancooper via wrote:
> Is grep able to take multiple search directories stored in an array like so
>
> grep -rl "$ptrn" ${dirlist[@]} |
You need quotes. "${dirlist[@]}"
This will pass the elements of the array as arguments to grep. What
your version of grep does with them after that is up to grep.
Remember, the shell constructs a command as a list of strings, and
passes them off to the kernel to execute. grep never sees an "array".
It only sees the expanded list of argument strings.
So, if this command works on your system:
grep -rl PATH /tmp /var/tmp
then the same command generated using an array expansion will also work.