title: Simple BASH string replacement
body: <p>I'm trying to replace instances of <code>{$pear_root}</code> in a config file with the <code>$PEAR_ROOT</code> variable in a shell script.</p>
  
  <p>Using the method from <a href="http://www.cyberciti.biz/faq/unix-linux-replace-string-words-in-many-files/" rel="nofollow">here</a> under "A Note About Bash Escape Character" I have:</p>
  
  <pre><code>ESC_PEAR_ROOT="${PEAR_ROOT//\//\\/}"
  sed -i "s/{\$pear_root}/${ESC_PEAR_ROOT}/"../.serverconfig/test.txt
  </code></pre>
  
  <p>I'm getting back <strong>34: Bad substitution</strong> which I think may mean that this is unsupported.</p>
  
  <p>The problem seems to be the use of <code>s/find/replace/</code>, as I get the same error whether doing this with <code>sed</code> or with <code>perl</code>.</p>
  
  <p>What is the simplest way to do this:</p>
  
  <pre><code>APP_ROOT=$(php ./scripts/get_realpath.php '../')
  PEAR_ROOT="$APP_ROOT/pear"
  ESC_PEAR_ROOT="${PEAR_ROOT//\//\\/}"
  sed -e "s/{\$pear_root}/${ESC_PEAR_ROOT}/"../.serverconfig/test.txt
  </code></pre>
  
  <p>And end up with all instances of <code>{$pear_root}</code> in <code>test.txt</code> replaced with the path from <code>PEAR_ROOT</code>?</p>
  
  <p>I'm not attached to this method - anything reliable will do.</p>