Bash variable scope

I want to search a repository file to see if I have a file in my directory. To do this, I loop the directory hopefully containing the file I am looking for, and I check to see if that file is in my repository.txt. If it is in there, I change a boolean, and then check the value of that boolean after I compared all the files in the repository.

for file in *
    cut -d, -f1 $repo | while read line
        echo "comparing "$line" == "$file" "
        if [ "$line" == "$file" ]; then
          echo "I got tripped!!" #inThere is true
          echo "in there is $inThere"
          echo "in there is $inThere" #inThere is false        

Is there a way I can persist the changing boolean value, or is there another, smarter way of doing this? Please let me know if you have any questions.


BASH FAQ entry #24: "I set variables in a loop that's in a pipeline. Why do they disappear after the loop terminates? Or, why can't I pipe data to read?"

while read ...
done < <(cut ...)

Need Your Help

How to generate the cartesian product of a jagged array?

c cartesian-product

I'm having some trouble figuring out how to generate the cartesian product of a jagged array. I have googled around, but i cant seem to find an implentation for a iterative language. So i'm trying to