Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables' names

Status
Not open for further replies.

ns705

Programmer
Feb 4, 2004
29
GB
Hi,
can somebody help me please with one problem?

In ksh script (AIX) I have some arrays- ar1, ar2, ar3 and so on.
I have some variable (e.g. j) that can be set to 1 or 2 or 3 and so on.
Depending of this index variable I should set members in ar1 or ar2 or ...
So I should have something about two-dimension array.

In which way I can do it? I mean to set ar$j array members?

Thank you for your time.

Nash
 
Oh, I'm very sorry!
Please, don't waste your time!
I have just found it can be done via eval.
Before I used eval in an incorrect way for this case.

Sorry fo bothering!

Nash
 
Try this :

i=2
set -A ar$i 00 11 22 33 44
eval ar$i[5]=55
eval echo \${ar$i[5]}



Jean Pierre.
 
Thank you, Jean Pierre

You confirmed that I acted in a right way.
But today seems not to be my day.
I went ahead and faced the next problem.
I need to check if some ar$j[$i] contains this or that value.
I need something about:
[[ "this-two-index-var" = "value" ]] && cmd-block
Is it possible to do it via eval?
I have confused with substitutions at all.

Thank you in advance.

Nash
 
Try :

eval [[ "\${ar$j[$i]}" = "value" ]] && cmd-block

Jean Pierre.
 
Jean Pierre,

thank you a lot for your help!
It really helped.

Nash
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top