while IFS= read -r name;name && IFS= read -r number; do IFS=#IFS= read -r number || break printf 'Your name is %s and your number is %d\n' "$name" "$number" done < answers.txt Your thought processes were on the right track, we need to bring in a loop, the while loop whose condition is a read command. Then in the body of the loop, we perform another read to get the number and print the pair of name<=>number read in.
On both theare read commands we place a break out condition upon failure. The one in the while is implicit whilst the one in the body we place a break statementjoined by an AND.