1

I have a problem with change value in array. I have several arrays: tab1, tab2.... etc. I want to change some value in these arrays using two variable:

x=2
y=3
tab$y[$x]="#"

it doesn't work. Could anyone help me?

2 Answers 2

5

Use declare, it's safer than eval:

declare tab$y[$x]="#"
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, and I didn't know this one works. Just for completion, is there an equally elegant way to get the value of ${tab$y[$x]}?
@ChenLevy: Not that I can think of, but there are probably better alternatives to this kind of thing anyway.
1

eval is your friend:

eval tab$y[$x]="#"

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.