我想搜索存储库文件,看看我的目录中是否有文件。为此,我循环包含我正在查找的文件的目录,并检查该文件是否在我的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 有没有一种方法可以持久化不断变化的布尔值,或者是否有另一种更智能的方法来实现这一点?如果你有任何问题请告诉我。
发布于 2012-09-10 08:11:52
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 ...
do
...
done < <(cut ...)https://stackoverflow.com/questions/12343981
复制相似问题