If you have two files with the same number of lines you can use the 'paste' command. This will merge lines from first and second file. If you want them to be separated by '-' you can use.
paste -d- a.txt b.txt
Use 'man paste' for more information.
If you do not want to use the paste command, you could obtain something similar to your script using the following script:
exec 3<> a.txt
exec 4<> b.txt
while [ $R1 -eq 0 -a $R2 -eq 0 ]; do
read A <&3
read B <&4
echo $A - $B
- the execs opens the two files and asigns them to file descriptors 3 and 4
- in R1 and R2 we store the results status of the read from the files
- the read command read in variables A (and B) a line from files descriptors 3 and 4
Note about your code: you have the for loops one into the other. So the 'inner' loop will execute completly for 1 iteration of the outer loop. This is not what you want....