I need to read lines from a file. Usually send the file in via stdin, but if I also need to do user input, I can't!
Here's a (contrived) example:
#!/usr/bin/env bash
cat <<HERE >/tmp/mytemp.txt
four of clubs
two of hearts
queen of spades
HERE
while read line ; do
echo "CARD: $line"
read -p 'Is that your card? ' answer
echo "YOUR ANSWER: $answer"
echo
done </tmp/mytemp.txt
This doesn't work. Instead you get this:
$ ~/bin/sample_script.sh
LINE: four of clubs
MY ANSWER: two of hearts
LINE: queen of spades
MY ANSWER:
$
How can I do both in the same loop?