help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] array indirection


From: John Kearney
Subject: Re: [Help-bash] array indirection
Date: Sat, 05 May 2012 02:27:04 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1

Am 05.05.2012 02:20, schrieb Bill Gradwohl:
Can anyone explain why one pass of this loop works and then fails.

If it didn't work at all, or worked all the time I could understand, but working once and then quitting is confusing.

array=(11 12 13 14 15)
variableName='array'

for ((x=0; x<address@hidden; ++x)); do
   echo "array[${x}]=${!variableName[$x]}"
done
==================
Produces:
address@hidden 01.ycc# ./tst pass3
array[0]=11
./tst: line 33: !variableName[$x]: unbound variable


--
Bill Gradwohl

AFAIK this syntax ${!variableName[$x]} isn't supported.

I'm guessing the reason the first one worked is because
${!variableName[0]} is a special case because
${!variableName[0]} is a synonym for ${!variableName}
and ${!variableName} is supported.




 


--
View
          John Kearney's profile on LinkedIn John
          Kearney

reply via email to

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