Skip to main content
deleted 244 characters in body
Source Link
user218374
user218374
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.

while IFS= read -r name; do 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 the 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 statement.

while IFS= read -r name && IFS= read -r number; do #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 are read commands joined by an AND.

Source Link
user218374
user218374

while IFS= read -r name; do 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 the 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 statement.