title: Insert a variable at line #1 of txt file using sed
body: <p>I have the following bash:</p>
  
  <pre><code>#!/bin/bash
  if ["$#" -ne "1"]; then
     echo "Usage: `basename $0` &lt;HOSTNAME&gt;"
     exit 1
  fi
  
  IPADDR=`ifconfig | head -2 | tail -1 | cut -d: -f2 | rev | cut -c8-23 | rev`
  sed -i -e '1i$IPADDR   $1\' /etc/hosts
  </code></pre>
  
  <p>But when I <code>cat /etc/hosts</code>:</p>
  
  <pre><code>$IPADDR
  </code></pre>
  
  <p>How can I deal with such issues? </p>