title: How to use variables in a command in sed?
body: <p>I have <code>abc.sh</code>:</p>
  
  <pre><code>exec $ROOT/Subsystem/xyz.sh
  </code></pre>
  
  <p>On a Unix box, if I print <code>echo $HOME</code> then I get <code>/HOME/COM/FILE</code>.</p>
  
  <p>I want to replace <code>$ROOT</code> with <code>$HOME</code> using sed.</p>
  
  <p>Expected Output: </p>
  
  <pre><code>exec /HOME/COM/FILE/Subsystem/xyz.sh
  </code></pre>
  
  <p>I tried, but I'm not getting the expected output:</p>
  
  <pre><code>sed  's/$ROOT/"${HOME}"/g' abc.sh &gt; abc.sh.1
  </code></pre>
  
  <hr>
  
  <p>Addition: </p>
  
  <p>If I have <code>abc.sh</code></p>
  
  <pre><code>exec $ROOT/Subsystem/xyz.sh $ROOT/ystem/xyz1.sh
  </code></pre>
  
  <p>then with </p>
  
  <pre><code>sed "s|\$INSTALLROOT/|${INSTALLROOT}|" abc.sh
  </code></pre>
  
  <p>it is only replacing first <code>$ROOT</code>, i.e., output is coming as </p>
  
  <pre><code>exec /HOME/COM/FILE/Subsystem/xyz.sh $ROOT/ystem/xyz1.sh
  </code></pre>