If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Arrays

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-21-03, 10:20
rnavanee rnavanee is offline
Registered User
 
Join Date: Jul 2003
Location: Chennai
Posts: 11
Arrays

$loop=1
while ..
do
eval period[$loop]=$monthName$year
echo $period[$loop]
...
done

How to assign a value to an array and how to retrieve the value?
Reply With Quote
  #2 (permalink)  
Old 07-21-03, 10:35
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
You're making this hard work for yourself, aren't you? :-)

array[0]=foo
array[1]=bar
echo "array[0] = ${array[0]}"
echo "array[1] = ${array[1]}"
Reply With Quote
  #3 (permalink)  
Old 07-21-03, 10:43
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
If you're using a variable as the index, you only need to code as follows...

i=2
array[$i]=foobar
echo ${array[$i]}

By the way, this could also be written...

i=2
eval eval eval eval eval array[$i]=foobar
eval eval eval eval eval echo ${array[$i]}

But I hope you can see that this would be unnecessary.

HTH

Last edited by Damian Ibbotson; 07-21-03 at 10:56.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On