I am trying to create nested array's dynamically from a string that has been parsed (parameter expansion) using a for loop in bash and I am failing:
user@server:/home/user> foo=one,two,three
user@server:/home/user> for i in ${foo//,/" "}; do echo ${i}; done
one
two
three
user@server:/home/user> for i in ${foo//,/" "}; do declare -a ${i}=(var1=foo var2=foo var3=foo); done
-bash: syntax error near unexpected token `('
I can create the nested array manually and it works:
user@server:/home/user> declare -a one=(var1=foo var2=foo var3=foo)
user@server:/home/user> echo ${one[*]}
var1=foo var2=foo var3=foo
Any help would be appreciated!