title: sed: Can't replace latest text occurrence including "-" dashes using variables
body: <p>Trying to replace a text to another with sed, using a variable. It works great until the variable's content includes a dash &quot;-&quot; and sed tries to interpret it.</p>
  <p>It is to be noted that in this context, I need to replace only the latest occurrence of the origin variable ${src}, which is why my sed command looks like this:</p>
  <pre><code>sed -e &quot;s:${source}([^${source}]*)$:${dest}\1:&quot;
  </code></pre>
  <p>&quot;sed&quot; is kind of new to me, I always got my results with &quot;replace&quot; or &quot;awk&quot; whenever possible, but here I'm trying to make the code as versatile as possible, hence using sed. If you think of another solution, that is viable as well.</p>
  <p>Example for the issue:</p>
  <pre><code># mkdir &quot;/home/youruser/TEST-master&quot;
  # source=&quot;TEST-master&quot; ; dest=&quot;test-master&quot; ; find /home/youruser/ -depth -type d -name '*[[:upper:]]*' | grep &quot;TEST&quot; | sed -e &quot;s:${source}([^${source}]*)$:${dest}\1:&quot;
  sed: -e expression #1, char 46: Invalid range end
  </code></pre>
  <p>Given that I don't know how many dashes every single variable may contain, does any sed expert know how could I make this work?</p>
  <p><em>Exact context: Open source project LinuxGSM for which I'm rewriting a function to recursively lowercase files and directories.
  Bash function I'm working on and comment here: <a href="https://github.com/GameServerManagers/LinuxGSM/issues/1868#issuecomment-996287057" rel="nofollow noreferrer">https://github.com/GameServerManagers/LinuxGSM/issues/1868#issuecomment-996287057</a></em></p>