I have a bash script that I mostly use in interactive mode. However, sometimes I pipe in some input to the script. After processing stdin in a loop, I copy a file using "-i" (interactive). However, this never gets executed (in pipe mode) 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
cp -i afile bfile
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?