Nested for loop in bash

Hi,

How to use values in one for loop to other for loop.

say "$sf_rel" variable has values "2011/W2 2011/G2" I want to use these values in inner for loop to process properly.

$branch variable has G2 and 6

What is happening is outer for loop $i has 2011/W2 it is entering into inner loop, after inner loop execution it is again going to outer loop. Now $i will have 2011/G2 and again inner for loop is getting executed.

I want first outer for loop executes then come to inner loop (only executes one time) then jump to outer loop, process second time come to inner loop executes second time(inner loop)

please clarify ...
what are you trying to do : copy file1 and file2 in multiple locations ???

by the way from a purely syntaxical point of view you should fix those at first :

for i in $sf_rel
do 
ip_localdir="data/s/$i/src/resources/com/s/util/"
code_localdir="data/s/$i/src/resources/com/s/code"

for j in $branch
do
ip_clientdir="$j/src/resources/com/util/geoip"
code_clientdir="$j/src/resources/com/util/code"

#Here i am using the variable of outer for loop
cp $HOME/file1.txt $HOME/$ip_localdir/
cp $HOME/file2.txt $HOME/$code_localdir/
done

done

But i am still not sure about what final goal you are trying to achieve

Hi,
...and a missing do after the second for.
Just filling in. :slight_smile:
And we assume that branch has the value "G2 6"?
And that the second loop contain something else because the variables You set there aren't used in it?

If it is possible for You, copy and paste the original code. And if that is what You have done, there are the mentioned syntactic errors, variable references and the "do". And try to state Your problem more clearly, for example desired output/result.

Best regards,
Lakris

Ooops, true ... fixed :slight_smile: