Results 1 to 3 of 3

Thread: Arrays

  1. #1
    Join Date
    Jul 2003
    Location
    Chennai
    Posts
    11

    Unanswered: 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?

  2. #2
    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]}"

  3. #3
    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 11:56.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •