I'm having problems working with an array in BASH. I've simplified the problem down to the following code:
#! /bin/bash
A1[0]="user1 user2 user3"
A1[1]="user4 user5 user6"
for each in ${!A1[*]}
do
echo -n "$each "
echo $A1[$each]
done
The output is as follows:
0 user1 user2 user3[0]
1 user1 user2 user3[1]
I can't understand why each line has the [X] in it (presumably an indication of the element of the array). How can I recover both the index and the data line from the array without the index appended to it ?
echo ${A1[$each]}.