[mdlug] Need help with bash array usage

Robert Citek robert.citek at gmail.com
Tue Jul 8 23:57:34 EDT 2008


Using arrays in a shell probably means that you are straddling the
border between coming up with overly clever ways to get the shell to
do what you want and switching to a more feature-rich scripting
language such as awk, perl, ruby, or python.

But then maybe you don't even need arrays:

$ find . -type f -iname "*.txt" -print0 |
xargs -0 grep -l "MATCH" |
awk '{print NR ": " $0 }'

Regards,
- Robert

On Tue, Jul 8, 2008 at 8:45 PM, Jeff Hanson <jhansonxi at gmail.com> wrote:
> Sample script and directories attached.  I'm trying to find files with
> a specific filename extension, containing a specific string, in a
> directory tree where directory and file names may contain spaces, then
> put it into an array with one complete path per element.  I can obtain
> a list with quoted paths and use command substitution to load it into
> the array but the assignment ignores the quotes and each element gets
> a space-delimited substring.  I think it's a word-splitting problem
> but am not sure how to fix it.



More information about the mdlug mailing list