Mac iTOps Tube

Sunday, May 6, 2012

bash loops

hello



i'm writing a script and I want to use a for loop inside a while loop as following:




Code:


while read line;

do       

    echo $line

       

    for i in $vrm;

        do

            echo $i

        done

done < './contacts'


when i use just the while loop it prints the lines from file ./contacts just fine

but when i put the for loop,first it prints the values of the variable $vrm and then the $line.Even more if i put an if statement inside the for loop it only works for the first line of the file.

Is there a priority of the loops?

Or am I doing something wrong in the script?




No comments:

Post a Comment