vendredi 27 février 2015

Values from two lists are not processing correctly within two nested loops


I am trying to pass some values contained in two lists to a simple echo within two nested for loops (the echo is used to look at what is generated inside the inner loop). But the results are not expected. I sure could use some guidance!


Using the bash shell. Here is the snippet:





a_list="0.05 0.10"
b_list="120.0 130.0"
c=44
x=555.0
for a in $a_list
do
for b in $b_list
do
echo $x $a $b $c
done
done




I expect this:



555.0 0.05 120.0 44
555.0 0.05 130.0 44
555.0 0.10 120.0 44
555.0 0.10 130.0 44


but I get this:



555.0 0.05 120.0 44
44.0 0.05 130.0
555.0 0.10 120.0 44
44.0 0.10 130.0


The 2nd and 4th lines are wrong. The 44 appears to echo first and overwrite the 555.0 . If I load the values of the lists directly into the for loop, it works OK. Like this:





c=44
x=555.0
for a in 0.05 0.10
do
for b in 120.0 130.0
do
echo $x $a $b $c
done
done


Thanks for any help and insights!



Aucun commentaire:

Enregistrer un commentaire