[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Passing multiple search directories to grep
From: |
Greg Wooledge |
Subject: |
Re: Passing multiple search directories to grep |
Date: |
Tue, 3 Aug 2021 07:32:53 -0400 |
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.
- Passing multiple search directories to grep, hancooper, 2021/08/03
- Re: Passing multiple search directories to grep,
Greg Wooledge <=
- Passing multiple search directories to grep, hancooper, 2021/08/03
- Re: Passing multiple search directories to grep, Greg Wooledge, 2021/08/03
- Re: Passing multiple search directories to grep, Andreas Kusalananda Kähäri, 2021/08/03
- Passing multiple search directories to grep, hancooper, 2021/08/03
- Re: Passing multiple search directories to grep, Alex fxmbsw7 Ratchev, 2021/08/03
- Re: Passing multiple search directories to grep, Andreas Kusalananda Kähäri, 2021/08/03
- Re: Passing multiple search directories to grep, Greg Wooledge, 2021/08/03
- Passing multiple search directories to grep, hancooper, 2021/08/03