On 25-06-2015 18:07, Patrick Burroughs (Celti) wrote:
A quick google and some personal testing showed me that the former doesn't work and the latter does, because bash doesn't interpolate variables in the middle of another variable like that; you need to use eval to make a second pass for it to work. Rather hacky, though, and I see no point in using it over the conditional construct proposed earlier — I just hate to see a suggestion that doesn't work out there.
Given that I was the one that suggested something that doesn't work without properly trying it first - sorry about that, how about this one: source_i686=("source1_i686.tar.gz" "source2_i686.tar.gz") md5sums_i686=('md5sum1_i686' 'md5sum2_i686') source_x86_64=("source1_x86_64.tar.gz" "source2_x86_64.tar.gz") md5sums_x86_64=('md5sum1_x86_64' 'md5sum2_x86_64') package() { local -n source="source_$CARCH" tarball="${source[1]}" echo "$tarball" tarball="${source[0]}" echo "$tarball" } CARCH=i686 package CARCH=x86_64 package No evals, but probably requires a quite recent bash version (no problem for arch I suppose). The output should look like: source2_i686.tar.gz source1_i686.tar.gz source2_x86_64.tar.gz source1_x86_64.tar.gz This means you can get any element of the source_{i686,x86_64} array at will via the source variable, this might be useful if there is more than one source in the array. -- Mauro Santos