title: Use a variable as replacement in bash sed command
body: <p>I am using the <code>sed</code> command on Ubuntu to replace content. </p>
  
  <p>This initial command comes from <a href="https://unix.stackexchange.com/questions/412835/append-text-with-echo-without-new-line">here</a>.</p>
  
  <pre><code>sed -i '$ s/$/ /replacement/' "$DIR./result/doc.md"
  </code></pre>
  
  <p>However, as you can see, I have a slash in the replacement. The slash causes the command to throw: </p>
  
  <blockquote>
    <p>sed: -e expression #1, char 9: unknown option to `s'</p>
  </blockquote>
  
  <p>Moreover, my replacement is stored in a variable. </p>
  
  <p>So the following <strong>will not</strong> work because of the slash:</p>
  
  <pre><code>sed -i "$ s/$/ $1/" "$DIR./result/doc.md"
  </code></pre>
  
  <p>As stated <a href="https://stackoverflow.com/questions/22182050/sed-e-expression-1-char-23-unknown-option-to-s">here and in duplicate</a>, I should use another delimiter. If I try with <code>@</code>:</p>
  
  <pre><code>   sed -i "$ s@$@ $1@" "$DIR./result/doc.md"
  </code></pre>
  
  <p>It gives the error:</p>
  
  <blockquote>
    <p>sed: -e expression #1, char 42: unterminated `s' command</p>
  </blockquote>
  
  <p>My question is:</p>
  
  <p><strong>How can I use a variable in this command as well as other delimiter than <code>/</code> ?</strong></p>