i am writing a script in which i take an input from user and find it in a file and replace it.
My input file looks like
hi
what your name?
allrise
my code looks is
echo "Enter the name"
read name
FILE="/opt/name.txt"
NEW_FILE="/opt/new_name.txt"
exec 0<$FILE
while read line
do
if [ -n "`echo ${line} | grep 'allrise'`" ]
then
echo ${line} | sed 's|allrise|hello $name|g' >>$NEW_FILE
else
echo $line >>$NEW_FILE
fi
done <$FILE
When i run my script, it ask me for name suppose i gave "john"... but the output comes as shown below
hi
what your name?
hello $name
so, can anyone explain how i can get proper output which should be.