title: Environment variable substitution in sed
body: <p>If I run these commands from a script:</p>
  
  <pre><code>#my.sh
  PWD=bla
  sed 's/xxx/'$PWD'/'
  ...
  $ ./my.sh
  xxx
  bla
  </code></pre>
  
  <p>it is fine.</p>
  
  <p>But, if I run:</p>
  
  <pre><code>#my.sh
  sed 's/xxx/'$PWD'/'
  ...
  $ ./my.sh
  $ sed: -e expression #1, char 8: Unknown option to `s' 
  </code></pre>
  
  <p>I read in tutorials that to substitute environment variables from shell you need to stop, and 'out quote' the <code>$varname</code> part so that it is not substituted directly, which is what I did, and which works only if the variable is defined immediately before.</p>
  
  <p>How can I get sed to recognize a <code>$var</code> as an environment variable as it is defined in the shell?</p>