find and replace problem

hi guys!!!

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.

hi
what your name?
hello john

Variables are not expanded inside single quotes; use double quotes:

echo ${line} | sed "s|allrise|hello $name|g" >>$NEW_FILE

Who don't you do:

sed "s/allrise/hello $name/" "$FILE" > "$NEWFILE"

There's no need for a loop.

thanks for reply..

Actually this is not my actual file... this is just dummy file which i created just to ask my query... anyways i will try your suggestion..

Duplicate of http://www.unix.com/shell-programming-scripting/110674-find-replace-query.html

(sock puppet)