please help in multiple for loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting please help in multiple for loop
# 1  
Old 01-10-2009
please help in multiple for loop

Hi
I have these data
0.9>i>0.1
0.45>j>0.01
I want to execute the script file for different number of i and j using the command
$ ./scriptfile i j
I write this code
#bin/bash
for ((i>0.1; i<0.9; i++))
for ((j>0.01; j<0.45; j++))
do
./scriptfile $i $j
done
However, for loop is not working with me. How can I fix the problem???
Regards
# 2  
Old 01-10-2009
Code:
You can use seq here:

$ for i in $(seq .1 .1 .9); do for j in $(seq .01 .01 .45); do ./script $i $j; done; done

And in your script you missed one set of "do" and "done"; but I can't make this work

 for ((i=.1;i<.9;i=i+.1))
** not sure why

but 

for ((i=1;i<9;i=i+1))
works fine.

# 3  
Old 01-10-2009
Thanks jaduks for the reply, but your code works only for the end values of i (i.e. i=.9) and j (i.e. j=.45) and I want to execute the file for all values of i and j which are in the range
0.9>i>0.1
0.45>j>0.01
# 4  
Old 01-11-2009
shell scripts use integer arithmetic that's why i=i+0.1 wont work..i did the same mistake and had to use bc command instead..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Multiple if within while loop ksh

Hi All, I'm trying to write while loop with multiple if conditions. Each and every if condition with different variables. whenever one if condition fails i have remove the file from filename and have to pick another file and loop should exit until the last file found in filename. Please help... (4 Replies)
Discussion started by: Kayal
4 Replies

2. Shell Programming and Scripting

Loop over multiple arrays

Hi All I need really really help with this :- I have two files ( File1 , File 2) both files are output of two different scripts. File1 usually has a list of names ( sometimes 3 names sometimes 5 sometimes more , depends about the output of the script) File2 usually has a list of numbers... (2 Replies)
Discussion started by: samsan
2 Replies

3. Shell Programming and Scripting

Reset while loop to loop same file multiple times

Hi, I want to read file multiple times. Right now i am using while loop but that is not working. ex. While read line do while read line2 do echo stmt1 #processing some data based on data., done < file2.txt done < file1.txt # This will have 10... (4 Replies)
Discussion started by: tmalik79
4 Replies

4. Shell Programming and Scripting

How to use for/while loop with multiple variables?

Hi, I have two variables like below which will always be of the same size a=1:2:3 b=A:B:C I need to use a for/while loop that will have both the variables available. I cannot use an array here and will probably might iterate through the variable as echo $a | tr ':' '\n' and thus iterate... (5 Replies)
Discussion started by: Elizabeth H
5 Replies

5. Shell Programming and Scripting

Multiple IP Loop

Hey all, I'm trying to do some very basic scripting. I been scouring the board looking at examples but I just can't seem to piece something together. Edit: Now that I look at it, maybe my request is a little more complex and I'm biting off more than I can chew... 1. Take a list of... (3 Replies)
Discussion started by: YouFatPenguine
3 Replies

6. Shell Programming and Scripting

Doing multiple tasks in a loop.

I am in the process of updating a folder of hundreds of recipe html files. I've already managed to modify a number of things in each file but I have run into something that's beyond my ability. I have a text file that I need to insert the contents into the html at a specific point. It creates... (0 Replies)
Discussion started by: Trapper
0 Replies

7. UNIX for Dummies Questions & Answers

multiple variables in for loop

hi, I want an equivalent for loop for this C code in unix shell script... for(int i,int j;i<5;i++,j++) { } Please reply soon Regards Navjot (1 Reply)
Discussion started by: navjotsingh
1 Replies

8. Shell Programming and Scripting

How to avoid multiple while loop?

Hi, How can I avoid multiple 'cat while read ....? in my script. In my script, I am taking the inputs from the temp text file and doing the ( cat while read input do ... ... done ) task and deleting later. I know it'll raise the perfomance issue. How to avoid this? (2 Replies)
Discussion started by: sharif
2 Replies

9. Shell Programming and Scripting

While loop with Multiple variables

Hi , I am trying to write a script in kshell with while loop ,its like count=1 count_cmp=1 while ; do tail -$count tempfile | head -1 > tempstring ....... done However i get CIF.sh: line 33: ' I have checked thetrailing spaces , not sure what is... (4 Replies)
Discussion started by: amit1_x
4 Replies

10. Shell Programming and Scripting

for loop with multiple variables ?

I have a script which selects two 'sets' of system LVM device files from a tabular file 'mapfile' using awk : LIVELV=`awk '{print($1)}' mapfile` BCVLV=`awk '{print($3)}' mapfile` I wanted to pass these 'sets' into an LVM command 'loop' along the lines of : lvmerge $BCVLV $LIVELV ie.... (3 Replies)
Discussion started by: fosterian
3 Replies
Login or Register to Ask a Question