[CentOS] Shell Script: Simple array usage = bad substitution?

James Bensley jwbensley at gmail.com
Fri Jun 19 12:43:31 UTC 2009

Hey Guys n Gals;

I have some arrays that I can't seem to expand correctly (if that's
the correct word?), imagine the following example:

myArray=("First" "Second" "Third")

First=("Monday" "Tuesdays" "Wednesday")
Second=("One" "Two" "Three")
Third=("A" "B" "C")

for ((i=0;i<${#myArray[@]};i++))
        for ((k=0;k<${#${myArray[$i]}[@]};k++)) # < Things go bad here!
                echo "${${myArray[$i]}[$k]}" # I understand this line
is won't work but it doesn't matter right now

So ultimatly we shall loop round each value in the myArray array and
print out the values in each array which has the same name as the
value in the myArray, array.

Where I have marked with a comment, the script stops with the error-

: bad substitution

I have looked on-line but I don't quite understand how I can correct
this? I have seen other people have this error for other problems but
not one like mine so I don't fully understand it? Can anyone explain
to me exactly what is going wrong and how I might correct it?

James ;)

  Version: 3.1
GIT/MU/U dpu s: a--> C++>$ U+> L++> B-> P+> E?> W+++>$ N K W++ O M++>$ V-
PS+++ PE++ Y+ PGP t 5 X+ R- tv+ b+> DI D+++ G+ e(+++++) h--(++) r++ z++

More information about the CentOS mailing list