Issue
Trying to assign value to a variable as follows
n=2
i='hello'
A$n='$i'
But getting error as "A2=hello: command not found
My aim is to assign 'hello' to A2 variable(by substituting $n as 2 in A$n)
Solution
You can use declare
to achive this:
n=2
i='hello'
# as glenn mentioned it's safer to quote the declaration
# because the variables could possibly contain spaces
declare "A$n=$i"
Answered By - jschuebel Answer Checked By - David Goodson (WPSolving Volunteer)