Incrementing variable in for


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Incrementing variable in for
# 8  
Old 01-27-2011
Let me explain better. I have this values:

Code:
res=0.0032
res1=0.41234
res2=0.42342
res3=0.4523
res4=0.23123
res5=0.12311

and i want to do a for so that i can get the values inside this variables:
Code:
c=6
maximo=$res
for (( c=$total-1; c>=0; c-- ))
do
if [ $maximo <= $res$c ];            
then
maximo=$valores
fi
done

But what when i do that it put the value of res just shows the value of the value res with the value of c in the front

---------- Post updated at 08:08 AM ---------- Previous update was at 07:25 AM ----------

I solved it. I done something like this:
Code:
maximo=$res
########################################
for (( c=5; c>=0; c-- ))
do
variavel=res$c 
varx=${!variavel}
echo $varx
if(( $maximo <= $varx ));            
then
maximo=$valores
fi
done

# 9  
Old 01-27-2011
Code:
res=0.0032
res1=0.41234
res2=0.42342
res3=0.4523
res4=0.23123
res5=0.12311

c=5
maximo=$res
while [ c -gt 0 ]
do
  eval "var=\$res$c"
  maximo=$(echo $var $maximo | awk '{print ($1>$2?$1:$2)}')
  c=$(( $c - 1))
done

echo $maximo

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing specific and incrementing lines of text from file via variable

This is part of a larger script where I need to pass only 1 line of a file to the script, based on a variable and not a direct reference. As part of a for loop : # for((line=0;line<50;line++)); do # awk ‘NR==$line' PhraseList.txt; done ... (5 Replies)
Discussion started by: Seth
5 Replies

2. UNIX for Dummies Questions & Answers

Help with incrementing the date

I have a date variable like 2012-12-31 ( YYYY -MM -DD ) in flat file and it has to be incremtented by 1 every time i run the script Example : i tried the below script after data modifcation but this does not seem to work expr `20121231 +%Y%m%d` + 1 Note : Mine is not a GNU... (4 Replies)
Discussion started by: akshay01987
4 Replies

3. Shell Programming and Scripting

incrementing the variable name along with the data?

Hello folks. I am trying to increment my variable names to match a counter that is to be used later on... Basically, i have a for loop that lists directories (for example TEST_OS DVP_OS PROD_OS ) but this loop is not static, it may contain 3 directory once and the next run 5 directories. I... (6 Replies)
Discussion started by: Stephan
6 Replies

4. UNIX for Dummies Questions & Answers

Incrementing Variable Names

Hi, I am using BASH. I have encountered a situation where the following is necessary (but I am not sure how to do it): #Define multiple arrays, whose names only differ by a number: ARRAY_1=(1 2 3) ARRAY_2=(4 5 6) ARRAY_3=(7 8 9) #Define ARRAY_AMOUNT, the number of arrays. In this case... (1 Reply)
Discussion started by: msb65
1 Replies

5. Shell Programming and Scripting

Facing problem in incrementing the variable

When I did, echo $SHELL in cmd prompt of putty, its displaying /bin/sh And in my shell script., I hav started with., #!/bin/sh and i=1; while ; do . . . i=$; (9 Replies)
Discussion started by: av_vinay
9 Replies

6. Shell Programming and Scripting

Incrementing with a twist - please help

I'm currently trying to write a ksh or csh script that would change the name of a file found in directories and attach to the name an incrementing three digit number. I know how to write a script that will go: 000, 001, 002, 003, etc The twist is I need more increments then allowed by a 3... (11 Replies)
Discussion started by: Rust
11 Replies

7. Homework & Coursework Questions

Incrementing Variable resets outside of while loop

1. The problem statement, all variables and given/known data: Variable is resetting to 0 after incrementing in while loop My bit of scripting displays the current users logged in the machine. Then it reads in a specific username and displays the processes for that user. The portion that I... (3 Replies)
Discussion started by: ratzlaff
3 Replies

8. Shell Programming and Scripting

Incrementing a variable is not happening

Hi All, Iam trying to increment a variable Following is the code #!/usr/bin/ksh i=1; i='expr $i+1'; echo $i; Output: expr $i+1 not able to understand why its happening in that way i was expecting result as 2... if the above method is worng .. can you help how i can get... (3 Replies)
Discussion started by: kiranlalka
3 Replies

9. Linux

Incrementing the date stored in the variable

Hi all, I have a variable with date as 20080831 . Now I want to increment it as 20080901 and so on.Is there any command for this. Please help me. thanks rameez (1 Reply)
Discussion started by: rameezrajas
1 Replies

10. Post Here to Contact Site Administrators and Moderators

No. post not incrementing

Hi Admin, i just noticed that when I do postings, the number does not increment. eg : Post A -Total Posts 312 Post B - Total Posts 312 Post C - Total Posts 313 Post D - Total Posts 313 Why is this so? Can you kindly check this out? Thank you. (5 Replies)
Discussion started by: incredible
5 Replies
Login or Register to Ask a Question