2 while read loops?

后端 未结 4 642
孤独总比滥情好
孤独总比滥情好 2020-12-20 00:49

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;         


        
4条回答
  •  一生所求
    2020-12-20 01:14

    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...

提交回复
热议问题