title: Using sed to replace unique text with URL
body: <p>I'm trying to figure out a more elegant way to replace a unique piece of text in a file with a URL.</p>
  <p>It seems that <code>sed</code> is interpreting the URL as part of its evaluation logic instead of just replacing the text from a bash variable.</p>
  <p>My file looks something like:</p>
  <pre><code>$srcRemoveSoftwareURL = &quot;softwareURL&quot;
  </code></pre>
  <p>and I'm attempting to (case-sensitive) search/replace <code>softwareURL</code> with the actual URL.</p>
  <p>I'm using a bash script to help with the manipulation and I'm setting up my variables like so:</p>
  <pre><code>STORAGE_ENDPOINT_URL=&quot;http://mywebsite.com&quot;
  
  sas_url=&quot;se=2021-07-20T18%3A42Z&amp;sp=rl&amp;spr=https&amp;sv=2018-11-09&amp;sr=s&amp;sig=oI/T9oHqzfEtuTjAotLyLN3IXbkiADGTPQllkyJlvEA%3D&quot;
  
  softwareURL=&quot;$STORAGE_ENDPOINT_URL/1-remove-software.sh?$sas_url&quot;
  
  # the resulting URL is like this:
  # http://mywebsite.com/1-remove-software.sh?se=2021-07-20T18%3A42Z&amp;sp=rl&amp;spr=https&amp;sv=2018-11-09&amp;sr=s&amp;sig=oI/T9oHqzfEtuTjAotLyLN3IXbkiADGTPQllkyJlvEA%3D
  </code></pre>
  <p>I then use sed to replace the text:</p>
  <pre><code>sed &quot;s|softwareURL|$softwareURL|&quot; template_file.sh
  </code></pre>
  <p>I recognize that <code>bash</code> is taking preference for the <code>$softwareURL</code> variable and inserting it in, but then <code>sed</code> interprets the URL as part of some evaluation logic.</p>
  <p>At the moment my resulting template file looks like so:</p>
  <pre><code>$srcRemoveSoftwareURL = &quot;http://mywebsite.com/1-remove-software.sh?se=2021-07-20T18%3A42ZsoftwareURLsp=rlsoftwareURLspr=httpssoftwareURLsv=2018-11-09softwareURLsr=ssoftwareURLsig=oI/T9oHqzfEtuTjAotLyLN3IXbkiIIGTPQllkyJlvEA%3D
  </code></pre>
  <p>It seems that <code>sed</code> is also finding any ampersand <code>&amp;</code> characters in the URL and replacing it with the literal <code>softwareURL</code>.</p>
  <p>What I'm doing now is to pipe the result to <code>sed</code> again and replace <code>softwareURL</code> with <code>&amp;</code> which seems a little inefficient.</p>
  <p>Is there a better way to do this?</p>
  <p>Any guidance is most welcome!</p>
  <p>Thanks!</p>