dynamically setting an array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting dynamically setting an array
# 1  
Old 03-21-2007
dynamically setting an array

Hi Gurus,

How do I dynamically set up an array. Below is my code

Code:
if [[ $tsk_count -gt 0 ]]
  then

  set ecomm_task_limit = '${ecomm_srvr[$j]}'
fi

Here, I want to set values in the array "${ecomm_srvr[$j]}" into ecomm_task_limit upon each iteration. Finally I want to display all the values in the new array "ecomm_task_limit" after all the iterations are complete.

Thanks in advance
# 2  
Old 03-21-2007
Using Korn Shell Arrays

The following is the code snippet of an ksh array implementation,

PHP Code:
#!/bin/ksh

set -A arr Hello world!! Iam Nagarajan Ganesan
set 
-A NewArray

let count
=0
while [[ count -le 4 ]] ; do
   
NewArray[${#NewArray[*]}]=${arr[$count]};
   
print "NewArr[$count]= \c"
   
print ${NewArray[$count]}
   ((
count=count+1))
done
print "The New Array Has: \c"
print ${NewArray[*]} 
OUTPUT:
PHP Code:
$  /tmp/arr.ksh
NewArr
[0]= Hello
NewArr
[1]= world!!
NewArr[2]= Iam
NewArr
[3]= Nagarajan
NewArr
[4]= Ganesan
The 
New Array HasHello world!! Iam Nagarajan Ganesan 
Hope this may help you. Please let us know if this doesn't work

Thanks
Nagarajan Ganesan
# 3  
Old 03-21-2007
Nagarajan,

Thanks for your timely help. Your code worked as expected..
# 4  
Old 02-06-2008
Any idea why my script doesnt work ?

#!/bin/ksh
set -A proc $x
x=top| grep siebmtshmw |awk '{print $6}'|sed 's/\%//'
print $x
set -A proc $x
print ${proc[0]}
print ${proc[1]}
print ${proc[2]}
___
In nut shell Im trying to use top to get the desired process and then store them in a array and print them ..
# 5  
Old 02-07-2008
Quote:
Originally Posted by vivsiv
#!/bin/ksh
set -A proc $x
x=top| grep siebmtshmw |awk '{print $6}'|sed 's/\%//'
print $x

set -A proc $x
print ${proc[0]}
print ${proc[1]}
print ${proc[2]}
___
In nut shell Im trying to use top to get the desired process and then store them in a array and print them ..
You have not mentioned how many iterations of top should run,so this will keep blocking on that statement.
Also the assignment line is incorrect.

Try this approach,
Code:
  set -A proc $(top -n 5 | grep siebmtshmw |awk '{print $6}')
  echo ${proc[*]}

Thanks
Nagarajan G
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Setting file permissions dynamically

I'm working in a linux server where wrappers are executed by multiple users of different groups. The log and output files are created with 554 permissions by default. This is stopping other users to run the wrappers unless the log and output files are deleted or given 777 permission. Setting SUID... (1 Reply)
Discussion started by: praveenpa
1 Replies

2. Shell Programming and Scripting

Dynamically setting of environment variable... Can it be done?

Hi all, I am fairly new to unix scripting and will like to know how to dynamically set the name of an environment variable to be used. We have a .env file where we defined the names and locations of data files, trigger files, directories .... etc Example of variables defined in .env... (4 Replies)
Discussion started by: Morelia
4 Replies

3. Shell Programming and Scripting

How to create dynamically associative array in PHP?

Hi, I have an html page like this: <html> <body> <form action="test.php" method = "post"> Enter your name:<input name="search" type = "text" size ="40"> <br> Enter your age:<input name="age" type = "text" size ="20"> <input type = "submit" name="submit" value="search"> <input type =... (1 Reply)
Discussion started by: vanitham
1 Replies

4. HP-UX

max limit in in setting array

hi, iam getting error when i assign a variable to an array of more that 315 character in length set -A array <variable> <variable> value is 000001 000002 and up to 000045 it is giving error as "The specified subscript cannot be greater than 1024." can any one help me to solve this (2 Replies)
Discussion started by: gomathi
2 Replies

5. Shell Programming and Scripting

set array name dynamically

Hi, I am trying to name a set of arrays dynamically named as @array_$i (The $i will mean that I obtain a set of arrays called: @array_1 @array_2 @array_3 etc. i tried various methods like @array_$i @{array_$i} etc. any ways to do this Thanks (4 Replies)
Discussion started by: esham
4 Replies

6. Shell Programming and Scripting

Setting array equal to command response

normally when i type: condor_q | tail -1 command line returns: 0 jobs; 0 idle, 0 running, 0 held I want use the number in front of 'running' in a series of equality tests to submit more jobs when my queue gets low. Someone showed me how to do it a few days ago by setting an array equal to... (4 Replies)
Discussion started by: pattywac
4 Replies

7. Shell Programming and Scripting

KSH Setting multiples variables with an array

ih all, info=$(get_Info $daemon) # $info give : # "ev20 8800 TTIOGC 12345 astos EDITEUR 0 0 . ." server=$(echo $info | cut -d" " -f1) port=$(echo $info | cut -d" " -f2) dname=$(echo $info | cut -d" " -f3) dport=$(echo... (1 Reply)
Discussion started by: wolfhurt
1 Replies

8. UNIX for Dummies Questions & Answers

How can i read array elements dynamically in bash?

Hi friends how can we read array elements dynamically in bash shell? (1 Reply)
Discussion started by: haisubbu
1 Replies

9. Shell Programming and Scripting

Setting values in an array? Easy one

I need to do something like this: KEYS= for key in $KEYS do echo $key done The KEYS are static values in my script, I'm just having trouble with setting them as separate values. Thanks! (3 Replies)
Discussion started by: TheCrunge
3 Replies
Login or Register to Ask a Question