bash: flushing stdin (standard input)
- by rahul
I have a bash script that gets some input as stdin. After processing, I copy a file using "-i" (interactive). However, this never gets executed since (I guess) standard input has not been flushed. To simplify with an example:
#!/bin/bash
while read line
do
echo $line
done
# the next line does not execute
read -p "y/n" x
echo "got $x"
Place this in t.sh, and execute with:
ls | ./t.sh
The read is not executed.
I need to flush stdin before the read. How could it do this?