LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 05-20-2006, 03:51 AM   #1
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Rep: Reputation: 31
bash arrays question


Hello.

I have the following arrays:

Code:
ARRAY_ONE[0]="hello"
ARRAY_ONE[1]="world"
ARRAY_ONE[2]="!"

ARRAY_TWO[0]="hello"
ARRAY_TWO[1]="linuxquestions"
ARRAY_TWO[2]="!"
[*note: just an example :-) ]

I have a name of the array I need (i.e. "ARRAY_ONE" or "ARRAY_TWO") stored in $ARR_NAME, and the element I need in $ARR_ELEM.

I.e.: $ARR_NAME could be "ARRAY_TWO" and $ARR_ELEM "0".

I need to print the information in $ARRAY_ELEM of $ARR_NAME.

"echo ${$ARR_NAME[$ARR_ELEM]}" doesn't work.
 
Old 05-20-2006, 04:07 AM   #2
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Original Poster
Rep: Reputation: 31
fixed: eval "\${$ARR_NAME[\$ARR_ELEM]}"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about outputing arrays with pointers, then just arrays... RHLinuxGUY Programming 1 04-12-2006 06:40 AM
bash script help (arrays and strings from files) nkoplm Programming 14 12-02-2005 10:50 AM
Generating iteratable arrays in bash d00bid00b Programming 4 08-15-2005 05:54 PM
bash script - variables & arrays question rblampain Linux - Software 4 09-25-2004 10:57 AM
bash for statement with 2 arrays? Noerr Linux - General 10 05-27-2002 01:58 PM


All times are GMT -5. The time now is 05:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration