I am trying to read a text file (line by line) and take user response in a while loop. However, the script does not wait to take input. Instead, it just prints all the text to screen.
JavaScript
x
while IFS= read -r line || [ -n "$line" ]; do
printf '%sn' "Store $line y or n: "
read input
if [ $input == "y" ]
then
echo $line >> saved_domains.txt
fi
done < "urls.txt"
The script only prints alternate text lines from the file (Please refer to the image below).
Advertisement
Answer
This worked for me:
JavaScript
exec 3<&0
while IFS= read -r line || [ -n "$line" ]; do
printf '%sn' "Store $line y or n: "
read -r -u3 input
if [ $input == "y" ]
then
echo $line >> saved_domains.txt
fi
done < "urls.txt"