Date: Wed, 01 Jul 2009 22:16:25 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Alexandre Vieira <nullpt@gmail.com> Cc: freebsd-questions@freebsd.org Subject: Re: scripting tip needed Message-ID: <87tz1wqkmu.fsf@kobe.laptop> In-Reply-To: <755cb9fc0907011040o28b82cdbjd5760b139f797050@mail.gmail.com> (Alexandre Vieira's message of "Wed, 1 Jul 2009 18:40:00 %2B0100") References: <755cb9fc0907011040o28b82cdbjd5760b139f797050@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 1 Jul 2009 18:40:00 +0100, Alexandre Vieira <nullpt@gmail.com> wrote:
> Hi folks,
>
> I'm having a little problem.
>
> For exambe in ksh:
>
> $ z=0
> $ y=1
> $ x=aaaa
> $ eval `echo MACHINE_DISK$z[$y]`=$x
> $ echo ${MACHINE_DISK0[1]}
> aaaa
>
> My problem is getting back the value of the variable using variables to
> refer to the variable name (confusing). I.e $MACHINE_DISK$z[$y] .
>
> Using ${} works great when you only have a simple array but adding a
> variable in the middle of the variable name seems to ruin it.
>
> $ echo ${MACHINE_DISK0[$y]}
> aaaa
> $ echo ${MACHINE_DISK$z[$y]}
> ksh: ${MACHINE_DISK$z[$y]}: bad substitution
My own short piece of (slightly off-topic) advice is:
``If you find yourself using arrays in bash, ksh or another shell,
now is a *very* good time to consider a more advanced scripting
language, like Perl or Python.''
Trying to coerce shell quoting to do a sensible thing with array syntax
is error-prone, annoying and --very often-- a waste of your time:
Using an interactive language like Python you can actually *test* the
code as you are writing it. This is a major win most of the time.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?87tz1wqkmu.fsf>
