user3597432
user3597432

Reputation: 131

Unix script , declare array

I try to declare an array and access its contents like this


declare -a VAR
VAR[0]=text1
VAR[1]=text2
VAR[2]=text3
echo $VAR[1]


But it doesn't work.
Can you fix my code and also tell me why we don't have to declare the size
of an array in UNIX when we declare it.

Upvotes: 0

Views: 104

Answers (1)

a5hk
a5hk

Reputation: 7834

declare -a VAR
VAR[0]=text1
VAR[1]=text2
VAR[2]=text3
echo ${VAR[1]}

Any element of an array may be referenced using ${name[subscript]}.

more info

Upvotes: 3

Related Questions