Reading Yes/No Option inside the loop, Does not wo

2019-07-21 20:37发布

问题:

while read line
do

read -p "Are you alright? (y/n) " RESP
if [ "$RESP" = "y" ]; then
  echo "Here i want to do something, but prompt does not wait for the answer"
else
  echo "You need more bash programming"
fi

done < find-spam-send-php-ver2.log

==> This script does not work. It does not "wait" for the yes or not option. Please I want this script to work. Please let me know, how do modify this. I have seen this kind of similar things in many linux installation scripts.

回答1:

I have not tested this but should work,

while read line <&3
do

read -p "Are you alright? (y/n):" RESP

if [ "$RESP" = "y" ]; then
  echo "Here i want to do something, but prompt does not wait for the answer"
else
  echo "You need more bash programming"
fi

done 3< find-spam-send-php-ver2.log


标签: linux bash shell