Counters and arrays help needed!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Counters and arrays help needed!
# 1  
Old 08-09-2007
Counters and arrays help needed!

I am trying to write a program in a script .sh

I have a list of coordinates ie
e1=123 n1=123
e2=456 n2=456
e3=789 n3=789

I have a counter starting at 1
for (( i=1; i<=2; i++))
i need coordinate=123,123
then on the second loop
coordinate=456,456 etc...

I tried doing:

Code:
#e=0 n=0 < just to show what e and n return
#Coordinates
e1=123 n1=123
e2=456 n2=456

coordinate = $e$i,$n$i

this will not work it returns 01,02

i need it to think coordinate=$e$i = $e1 = 123
and coordinate=$n$i = $n1 = 123

can any one help?

Thanks

Gary
# 2  
Old 08-09-2007
Hi gazz1982,

I dont think using a variable name like that should work.

take a look at arrays:
http://tldp.org/LDP/abs/html/arrays.html

or a more ugly hack:
e="123,456,789"

echo $e | cut -d , -f $counter
# 3  
Old 08-09-2007
Place all your coordinates separated by space into a file:
Code:
123 123
456 456
789 789

Write a shell as following:
Code:
while read mX mY
do
  echo 'X = '${mX}' Y = '${mY}
done < CoordFile

# 4  
Old 08-18-2007
hi
i think you want
eval coordinates=\$e$i,\$n$i

without eval
coordinates=\$e$i,\$n$i
evaluates (for i=1) to
coordinates=$e1,$e2
(you can check this by calling
echo coordinates=\$e$i,\$n$i
eval gives an extra evaluation, that is, it evaluates
coordinates=$e1,$e2

mfg guenter
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to print based on the value from counters?

Hi, I am writing a script which will get the input from a combinations of awk commands and using counters and loop I am generating a dynamic values and passing the output to a file using print -u3 options, now instead of redirecting the output to a file how can the output be created in the same... (3 Replies)
Discussion started by: shruthidwh
3 Replies

2. Programming

Arrays in C++

I've noticed something interesting in C++ programming. I've always done tricky stuff with pointers and references to have functions deal with arrays. Doing exercises again out of a C++ book has shown me an easier way, I didn't even know was there. It's weird to me. When dealing with arrays, it... (4 Replies)
Discussion started by: John Tate
4 Replies

3. Programming

question about int arrays and file pointer arrays

if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Discussion started by: omega666
1 Replies

4. Shell Programming and Scripting

using existing variables as counters in a "for" loop ?

Hi all, I am rather new to shell programing I am trying to run a loop through variables that already exist, here is (a part of ) the code, variables param_kz etc already exist (in the same file, i do not run another script file etc) and have values assigned to them (strings, "y" or "n") echo... (1 Reply)
Discussion started by: babulin2002
1 Replies

5. Web Development

PHP arrays in arrays

PHP question... I have an SQL query that's pulled back user IDs as a set of columns. Rather than IDs, I want to use their names. So I have an array of columns $col with values 1,7,3,12 etc and I've got an array $person with values "Fred", "Bert", "Tom" etc So what I want to do is display the... (3 Replies)
Discussion started by: JerryHone
3 Replies

6. Shell Programming and Scripting

Arrays

Dear all, How can i unset arrays. I mean all the subscripts including the array after using them. Could you direct me to some links of array memory handling in the korn shell. Thanks (2 Replies)
Discussion started by: earlysame55
2 Replies

7. UNIX for Dummies Questions & Answers

Unix performance monitoring counters

Which performance counters you might to define as "The most important counters in checking unix performance" (3 Replies)
Discussion started by: gen4ik
3 Replies

8. Solaris

netstat counters

Is there a way to reset the netstat counters in solaris 8? Specifically, the error counters? (1 Reply)
Discussion started by: tjlst15
1 Replies
Login or Register to Ask a Question