title: How to remotely edit a line containing double quotes and variables using sed across ssh?
body: <p>I have a <code>sed</code> command that works perfectly if I run it locally on Ubuntu or our embedded client Arago:</p>
  
  <pre><code>sed -i 's/export PART="$1"/export PART="A"/' flash.sh
  </code></pre>
  
  <p>This results in exactly what I need on both versions of <code>sed</code>, a line that changes:</p>
  
  <pre><code>export PART="$1"
  </code></pre>
  
  <p>to</p>
  
  <pre><code>export PART="A"
  </code></pre>
  
  <p>My problem is, I need to run that same command across a network to the embedded client so I tried this on an Ubuntu server using bash, to an Arago client using sh:</p>
  
  <pre><code>ssh -n -o stricthostkeychecking=no root@10.14.150.113 sed -i 's/PART="$1"/PART="A"/' flash.sh
  </code></pre>
  
  <p>Which results in a line that contains:</p>
  
  <pre><code>export PART=A"$1"
  </code></pre>
  
  <p>The substitution command needs to stay inside the single quotes so the double quotes are passed as literals, or maybe there's a better way to keep the double quotes in the two strings?  This looks to me like the <code>$1</code> is simply being ignored like it's empty and the <code>"A"</code> is being passed as <code>A</code> and replacing the end of <code>PART=</code>.  I've tried encapsulating the command in single and double quotes, which both result in the same thing.  I've also tried escaping the quotes with backslashes, same result.  I think this is something with quote expansion with sh that I simply don't understand.  Or possibly something I don't understand with ssh.</p>
  
  <p>I've read through a number of other threads that are similar, but none of them dealt with using ssh to run the command remotely.  I'm no longer a novice at sed, but this one has become quite the puzzle for me.</p>