Bash变量范围

时间:2012-09-10 00:00:11

标签: bash variables scope

我想搜索一个存储库文件,看看我的目录中是否有文件。为此,我循环了希望包含我正在寻找的文件的目录,并检查该文件是否在我的repository.txt中。如果它在那里,我更改一个布尔值,然后在我比较存储库中的所有文件后检查该布尔值。

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

有没有办法可以保持更改的布尔值,还是有另一种更聪明的方法可以做到这一点?如果您有任何问题,请与我们联系。

相关问题