I'm new to BASH and i'm trying to create a script which is simply put a large find and replace file. This is what I have so far
N=0
while read LINE ; do
N=$\(\(N\+1\)\)
sed 's/'$2'/'$3'/g' $LINE > .temp
echo "Changes to file $N = $LINE"
echo 'The following changes will be made will be made to $LINE :'
diff .temp $LINE
echo 'Are you sure you want to make these changes? y/
readline a
if [[ $a == "N" || $a == "n" || $a == "No" || $a == "no" ]]; then
echo "No changes have been made to $LINE"
rm .tempfr
elif [[ $a == "Y" || $a == "y" || $a == "Yes" || $a == "yes" ]]; then
mv .tempfr $LINE
echo "The given changes have been made successfully"
else
echo $a "is not a recognized input. Please use y/n"
fi
rm .temp
done < $1
For this code the $1 is a file which is simply a list of files which need to be searched with this find and remove script. $2 is the word that i'm looking to find and $3 is the word i'm looking to replace it with. The problem that I seem to be having is that every time that I run this script it seems to skip the
read a
line, and assumes that the user put in no input. I'm worried that this has something to do with using two read commands but I don't exactly know what the problem would be. Does anyone know why it isn't allowing me to ask for user input from inside this while loop?