I cannot see what you are really trying to do, but hope one of these two syntaxes will help - either reading two lines at a time, or loading the parameters into an array an re-using them.
So, if your file.txt
looks like this:
line 1
line 2
line 3
line 4
line 5
line 6
Example 1 - with two reads
#!/bin/bash
while read a && read b; do
echo $a, $b
done < file.txt
Output
line 1, line 2
line 3, line 4
line 5, line 6
Example 2 - with a bash array
#!/bin/bash
declare -a params
while IFS=$'
' read -r z; do
params+=("${z}")
done < file.txt
# Now print the elements out
for (( i=0;i<${#params[@]};i++ )) do
echo ${params[$i]}
done
Output
line 1
line 2
line 3
line 4
line 5
line 6
Example 3 - with GNU Parallel
Or, as I suggested in my comment, use GNU Parallel
like this
parallel -k -L2 echo {1} {2} < file.txt
Output
line 1 line 2
line 3 line 4
line 5 line 6
where -k
means "keep the output in order" and -L2
means "take 2 lines at a time from file.txt".
This has the advantage that, if you want to run 8 scripts at a time in parallel, you just specify -j 8
to parallel
and the job is done.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…