Re: bash array names with variables
Jared Fowkes <[email protected]> Mon, 22 Oct 2012 11:59:14 -0400
| Newsgroups | gmane.org.user-groups.jaxlug |
|---|---|
| Message-ID | <CALPN7-_86R_bm8n+qxMHOtCC11ky-dko1jbQKTQVy7iouhqQpQ@mail.gmail.com> |
From what I've read bash doesn't support 2 dimensional arrays, however there are a few tricks you can find at the link below. http://www.commandlinefu.com/commands/view/7921/tricky-implementation-of-two-dimensional-array-in-bash . On Oct 22, 2012 11:49 AM, "Tim Holloway" <timh-kiPKLF+HnOy1Z/[email protected]> wrote: > 2 dimensional arrays: e.g. a[$i][$j] = "X" > > ??? > > Tim > > On Sat, 2012-10-20 at 23:37 -0400, Robert Mckennon wrote: > > Is it possible to use a variables in an array name? > > > > I'm having a hell of a time getting it to work. > > > > for instance: a_0[x], a_1[x]...etc defined as: a_$i[x] > > > > I use a loop to create the arrays a_$i > > and then try and access them with: > > > > arrayname=a_$i > > nextarray=a_$(( $i + 1 )) > > > > > > I found I can get the data out of an array with a variable-name like > > so: F[$i]=$(eval echo \${$arrayname[$N]}) > > > > and that works... (found that tip here > > > http://www.linuxquestions.org/questions/programming-9/bash-loop-over-variable-array-names-705702/ > > ) > > > > > > But when trying to put data into the variable-named arrays is where > > I'm running into issues. > > > > 52 if [ $j != $N ]; > > 53 then > > 54 { > > 55 $nextarray[$k]=$(eval echo \${$arrayname[$j]}) > > 56 k=$(( $k + 1 )) > > 57 } > > 58 fi > > > > ./random.sh: line 55: a_4[0]=: command not found > > > > I've tried escaping it every way I can think of and google for, but > > I'm about done banging my head against the wall... > > > > > > Any suggestions??? > > > > Rob. > > > > --------------------------------------------------------------------- > > Archive http://marc.info/?l=jaxlug-list&r=1&w=2 > > RSS Feed http://www.mail-archive.com/[email protected]/maillist.xml > > Unsubscribe [email protected] > > > > --------------------------------------------------------------------- > Archive http://marc.info/?l=jaxlug-list&r=1&w=2 > RSS Feed http://www.mail-archive.com/[email protected]/maillist.xml > Unsubscribe [email protected] > >