On Fri, Jun 19, 2009 at 8:43 AM, James Bensley wrote:
> 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:
>
> #!/bin/bash
> myArray=("First" "Second" "Third")
>
> First=("Monday" "Tuesdays" "Wednesday")
> Second=("One" "Two" "Three")
> Third=("A" "B" "C")
>
> for ((i=0;i<${#myarr...@]};i++))
> do
>for ((k=0;k<${#${myarray[$i...@]};k++)) # < Things go bad here!
>do
>echo "${${myArray[$i]}[$k]}" # I understand this line
> is won't work but it doesn't matter right now
>done
> done
>
> 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?
>
How about this? Avoids the c=like for loop increments and just uses
the array elements for the next loop ...
#!/bin/bash
myArray=("First" "Second" "Third")
First=("Monday" "Tuesdays" "Wednesday")
Second=("One" "Two" "Three")
Third=("A" "B" "C")
for i in ${myarr...@]}; do
for k in ${i}; do
eval tmp=\${...@]}
echo ${TMP}
done
done
-Bob
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos