bash: flushing stdin (standard input)
Posted
by rahul
on Stack Overflow
See other posts from Stack Overflow
or by rahul
Published on 2010-06-18T07:55:19Z
Indexed on
2010/06/18
8:03 UTC
Read the original article
Hit count: 301
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?
© Stack Overflow or respective owner