I have a file "in" that contains:
a
b
c
I run the following command:
cat in | while read el; do select yn in "yes" "no"; do echo $yn; done; done;
And get the following output:
1) yes
2) no
#?
#?
#?
What I want is to be able to type 1 or 2 at each iteration. What do I need to do differently to make this work?
You're piping input into a while loop. Within the loop, stdin comes from the preceding command, not from the console. Your
select
statement is reading from the same pipe that theread
statement is reading from.Also, you don't need
cat
.You need to preserve stdin for use in the select statement. Try this:
First, note that we're redirecting input using '<', rather than using
cat
.This preserves your origin stdin (fd 0) in fd 4, and then inside the loop redirects input to
select
from fd 4.select
will read an input and execute it repeatedly until EOF; what you almost certainly want is the superficially similar: