is it possible to create a loop that makes associative arrays in bash?
I would like something along these lines....
number_of_servers=10;
COUNTER=1
while [ $COUNTER -le ${number_of_servers} ]; do
declare -A "server_${COUNTER}"
COUNTER=$((COUNTER+1))
done
many thanks !
declare -A server_{1..10})eval, but personally I try to steer clear ofeval.eval. For example,declare -A $(printf 'server_%d ' $(seq 1 $number_of_servers)). (Note the space in the printf format.) But if you are going to use a loop, use a for loop:for ((i=1;i<=number_of_servers;++i)); do declare -A server_$i; donedeclare -A foois only assigning an attribute to the namefoo. But I founddeclare -pfor checking if something has been declared.