Article 53BGV Shell Scripting: while read line from file + user input inside while loop

Shell Scripting: while read line from file + user input inside while loop

by
ondoho
from LinuxQuestions.org on (#53BGV)
I have a fairly standard while loop that reads strings from a file like this:
Code:while read -r line; do
read -r -p "Give me some input " answer
if [[ "$answer" ... etc.
done <fileThis (nested reads from stdin) clearly doesn't work as desired.

I tried searching for a solution for this specific problem but did not see anything that clearly mentions it.

I did come up with this:
Code:while read -r -u3 line; do
read -r -p "Give me some input " answer
if [[ "$answer" ... etc.
done 3<fileSo, I open a file descriptor 3 and read the lines from that, while user input goes through stdin.
This works as desired.

But - and as I said, I could not formulate the search terms to find any clear answers - is it OK to do this? Is it the proper way? Any pitfalls there?

PS: I use bash.latest?d=yIl2AUoC8zA latest?i=h68WQKqGwUs:0zKX6X8D6bg:F7zBnMy latest?i=h68WQKqGwUs:0zKX6X8D6bg:V_sGLiP latest?d=qj6IDK7rITs latest?i=h68WQKqGwUs:0zKX6X8D6bg:gIN9vFwh68WQKqGwUs
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments