I am trying to compare the content of file2 with that of file1 and based on that I need to take some action.
But when I try to take input from user (in variable answer) whether to start or not, the program does not wait for user input and takes value assigned to variable line automatically.
#!/bin/bash
while read line;
do
var=`grep $line file1.txt`
if [ -z "$var"]
then
echo "$line is not running"
echo "Do you want to start? (Y/N)"
read answer
if [ "$answer" = 'Y' ] || [ "$answer" = 'N' ]
then
if [ "$answer" = 'Y' ]
then
(some action)
else
(action)
fi
else
(action)
fi
fi
done < file2
whilereadand the closing backtick is missing. In addition, you wroteanswerinstead of$answerin the second conditional.