how to do variable expansion on files with eval

one can use a text file as a template to be expanded by the shell using eval. for this example, the template file is template, output is going to the file output, and the shell script is named changeit. their contents:

template

my home is: $HOME
my mailbox is: $MAIL
the time is currently: `date`

changeit

     #!/bin/sh
     cat template |
     while read line ; do
       eval echo $line
     done > output

after running this, the output file looks like:

 my home is: /home/dcapella
 my mailbox is: /var/mail/dcapella
 the time is currently: Mon Aug 1 15:20:09 PDT 2011

updated: Mon Aug 1 15:12:58 PDT 2011