I have a simple script which reads lines from a file (using a while-read loop) and asks the user whether to perform an action on each entry. The problem is that when I use read to prompt the user input, the user read gets data from the file read. Here is the code:
#!/bin/bash
[ -f "download.list" ] || exit 1
while read LINE
do
URL=${LINE#*,}
TITLE=${LINE%,*}
echo "Download $TITLE [y/n]: "
read RESPONSE
if [ $RESPONSE = 'y' ]; then
echo "curl -O $URL"
fi
done < download.list
The $LINE, $URL & $TITLE are set correctly. What happens is that $RESPONSE is set to the next line in 'download.list' rather than prompting the user for input.
Can anyone tell me what I am doing wrong?
Thanks,