bug-bash
[Top][All Lists]
Advanced

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

Re: create array in loop with variable in array's name


From: DennisW
Subject: Re: create array in loop with variable in array's name
Date: Wed, 08 Dec 2010 15:48:37 -0000
User-agent: G2/1.0

On May 28, 6:04 pm, pikta <pi...@post.sk> wrote:
> Hi all,
> I'm just a beginer and I got stucked .... I'm trying to create multiple
> array with variable in array's name. I would expect to have 3 arrays and
> each of them would contain 3 elements like array1=(a b c)  array2=(a b c )
> array3=(a b c) ; what means that first element of array1[0]="a" and for
> example third element of array3[2]="c". This is the way how I do it :
>
> for (( n=1; n<4; n++ ))
> do
> array$n=(a b c)
> done
>
> ...but there is syntax error.... and I can not fix it. I know I can declare
> these 3 arrays as :
> array1=(a b c)
> array2=(a b c)
> but this is just a simple example; in fact I want to read from several files
> to array$n and I can not go through ... can I declare array's name with some
> variable in it's name???? pls help; thanks in advance for any hint
> --
> View this message in 
> context:http://old.nabble.com/create-array-in-loop-with-variable-in-array%27s...
> Sent from the Gnu - Bash mailing list archive at Nabble.com.

For security reasons it's best to avoid eval whenever possible (http://
mywiki.wooledge.org/BashFAQ/048).

Try this:

for (( n=1; n<4; n++ ))
do
    declare -a array$n='(a b c)'
done


reply via email to

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