title: How can I escape a single quote correctly in when using/parsing a remote variable?
body: <p>I am trying to escape the following variable which is located on a remote server:</p>
  
  <pre><code>ssh root@$HWNODEIP "echo '    set root='$getgrub''   &gt;&gt; /etc/grub.d/40_custom"
  </code></pre>
  
  <p>In short I need to add a <strong>single quote before and after</strong> the variable <strong>$getgrub</strong>.</p>
  
  <p>I tried several things like putting them in double quotes (") and escaping () it, however no luck. The only result I am getting is similar things like: "sed: -e expression #1, char 43: unknown option to `s'"</p>
  
  <p>What am I doing wrong and what is the correct way to make this work?
  I also tried storing the $getgrub variable with single quotes included, however they don't appear in the file /etc/grub.d/40_custom?!</p>
  
  <p>Probably I am making somewhere a mistake, but I cannot seem to find it.</p>
  
  <p>Thanks.</p>
  
  <p>//edit</p>
  
  <p>If I run the following command from the server:</p>
  
  <pre><code>ssh root@$HWNODEIP  "echo '    set root='$getgrub'' &gt;&gt; /etc/grub.d/40_custom"
  </code></pre>
  
  <p>And I check the file the variable is in the file, however not with the single quotes in front and behind?</p>
  
  <p>Output (cat) of the file:</p>
  
  <blockquote>
    <p>set root=EXAMPLE</p>
  </blockquote>
  
  <p>Where it should read:</p>
  
  <blockquote>
    <p>set root='EXAMPLE'</p>
  </blockquote>
  
  <p>Strange...</p>