2 while 读循环? [英] 2 while read loops?
本文介绍了2 while 读循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我制作的脚本的目的是比较两个文件,同时读取其中包含文件路径名的列表...
So the object of the script I'm making is to compare files from two while read lists that have file path names in them...
while read compareFile <&3; do
if [[ ! $server =~ [^[:space:]] ]] ; then #empty line exception
continue
fi
echo "Comparing file - $compareFile"
if diff "$compareFile" _(other file from loop?_) >/dev/null ; then
echo Same
else
echo Different
fi
done 3</infanass/dev/admin/filestoCompare.txt
我需要能够通过两个 while 读取循环同时比较来自两个不同列表的文件......这可能吗?
推荐答案
我想我会按照以下思路重新构建:
I think I would restructure that along these lines:
while true
do
read -u3 line1 || break
read -u4 line2 || break
# do whatever...
done 3< file1 4< file2
使用单个循环,当在任一输入文件上到达文件末尾时将退出该循环.如果你想完整地阅读这两个文件,逻辑会稍微复杂一点,即使一个提前结束......
That uses a single loop, and will exit that loop when end of file is reached on either input file. The logic would be a little more complicated if you want to read both files entirely, even if one ends early...
这篇关于2 while 读循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文