The second read
inside the body of the loop is incorrect here. It actually goes one line ahead than your first read
call as part of the while loop. So for your requirement just read those variables as part of the first read
while read -r path1 path2; do
echo "$path1"
echo "$path2"
done < "$1"
As you see here, setting IFS=
is also incorrect, when reading two variables because, resetting the field separator just picks up the line as a whole. By having its default value (white-space characters of space, tab, and newline) reading two variables will store the values from each line in a space separated list. This way we could have n-column delimited line and use n variables to read.
Now the values are available in those variables which you could pass to other commands as needed.
Let see how this works for a sample input file
foo bar
foo1 bar1
foo2 bar2
Running the first script in debug mode with -x
set
$ bash -x script.sh
+ read -r path1 path2
+ echo 1
1
+ echo 2
2
+ read -r path1 path2
+ echo 3
3
+ echo 4
4
+ read -r path1 path2
+ echo abc
abc
+ echo def
def
+ read -r path1 path2