Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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)
A$n
$i
i
A$n='$i'
=
You can use declare to achive this:
declare
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"
Add a comment
declare "A$n=$i"
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
A$nwill be set to$inot the value ofi.A$n='$i'simply is not a valid assignment statement, syntactically. Assignments are recognized by the parser before any parameter expansion occurs, and the portion before the=must be a valid identifier, whichA$nis not.