[mdlug] Need help with bash array usage
Jeff Hanson
jhansonxi at gmail.com
Wed Jul 9 19:26:44 EDT 2008
On Wed, Jul 9, 2008 at 2:05 AM, Robert Meier <list1c30fe42 at bellsouth.net> wrote:
> The solution is to treat double quotes as the normal way to insert a
> variable's contents into the command stream.
> # quotes redundant but good habit for all reads
> bash> matching_files="$(find "arraytest" -type f -iname '*.txt' \
> -exec grep -l "MATCH" "{}" \; )"
> bash> x=0
> bash> echo "$matching_files" | while read f # quote read, but not assignment
> bash> do
> bash> echo "$x: $f" # quote string read
> bash> ((x++)) # but not numeric read
> bash> done
Helpful tips but doesn't really solve my problem. Like Brian's
suggestion I could rewrite the script and do everything within a
while/read loop but can't assign the output to an array to use outside
the loop. If I assign it without a subscript it succeeds but
everything ends up in one element. If I try to use a subscript with
the assignment to assign the value to a specific element I get a
"cannon assign list to array member" error.
More information about the mdlug
mailing list