The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem assigning values to variable finalight Shell Programming and Scripting 2 05-19-2008 10:56 PM
How to use array values after the loop. Devesh5683 Shell Programming and Scripting 1 05-13-2008 07:38 PM
incorrect array values jhillier UNIX for Dummies Questions & Answers 6 01-04-2008 04:44 AM
assigning values to a variable trichyselva UNIX for Dummies Questions & Answers 3 12-14-2007 01:55 AM
Problem in assigning values to variables mohanprabu Shell Programming and Scripting 3 08-25-2005 04:44 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-12-2005
yongho yongho is offline
Registered User
  
 

Join Date: Jun 2005
Location: New York City
Posts: 95
Assigning values to an array

The way I've been using arrays currently have been:

Code:
#!/bin/ksh

set -A myArray

myArray[0]=value1
myArray[1]=value2
myArray[2]=value3
myArray[3]=value4
Is there a way I can assign values to an array that will automatically place the value into the next element in the array like:

Code:
myArray=value1
myArray=value2
myArray=value3
myArray=value4
Without doing:

Code:
set -A myArray value1 value2 value3 value4
Because it's hard to follow if you're reading code and you need to manually feed your array 40 values.
  #2 (permalink)  
Old 07-12-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
set -A myArray value1 value2 value3 value4
  #3 (permalink)  
Old 07-12-2005
yongho yongho is offline
Registered User
  
 

Join Date: Jun 2005
Location: New York City
Posts: 95
Sorry gersh, I edited my post after you posted.
Is there another alternative to set -A myArray value1 value2 value3 value4 ?
  #4 (permalink)  
Old 07-12-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by yongho
Sorry gersh, I edited my post after you posted.
Is there another alternative to set -A myArray value1 value2 value3 value4 ?
well.... you can read the content of the file into an array like so:
Code:
#!/bin/ksh

set -A array $(<y0.txt)

typeset -i i=0;
while (( i < ${#array[*]} ))
do
  echo "${i} -> [${array[$i]}]"
  (( i+= 1 ))
done
Or you can set array cell to values in a loop - something similar to the above.
  #5 (permalink)  
Old 07-13-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Write a function:

Code:
$ cat loadr
#! /usr/bin/ksh
function loadr
{
        array[index]=$1
        ((index=index+1))
        return 0
}
index=0
loadr cat
loadr dog
loadr mouse

set | grep array
exit 0

$ ./loadr
array[0]=cat
array[1]=dog
array[2]=mouse
$
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0