[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bash 3.2.9, constructing array references with indirect expansion

From: Misfortunado Farmbuyer
Subject: bash 3.2.9, constructing array references with indirect expansion
Date: Wed, 5 Sep 2007 17:56:56 -0400

I've been staring at Chet's message in
for a while, and now I understand why my own script (doing something
similar) was not originally working.  What I can't quite figure is what
to change.

I'm source'ing a series of assignments of the form
        DIRS_name1=(/foo /bar /baz)
        DIRS_name2=(/qux /quux)
and earlier in the file, a list of the arbitrary 'name's are assigned.
Running through the list of 'name's and composing the corresponding array
variable name is no trouble, but I can't manage to indirect through to the
entire array.  Like the person I linked to above, I keep ending up with only
the first member of the array:

        declare -a a=${!v}
        # references through a are only scalar

I also tried reconstructing a copy of the array -- I don't care how slow or
inefficient that might be, it's going to be lost in the noise compared to
the real work of the script -- but didn't even get that much:

        declare -a a=( "address@hidden" )
        # references through a are empty

The FAQ mentions that indirect expansion and arrays exist, but doesn't give
examples of combining them (granted it's not that FA of a Q).  Staring at
the man page is how I got to where I am.  :-)  I've been looking at the
"advanced scripting guide" but their examples of indirection are all with
strings inside functions.

Any advice would be appreciated.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]