title: Bash: Using SSH to start a long-running remote command and collect its PID
body: <p>When I do the following, then I have to press <code>CTRL-c</code> afterwards or the shell acts weird. Left/right arrows keys e.g. doesn't move correctly and the text is messed up.</p>
  
  <pre><code># read -r pid &lt; &lt;(ssh 10.10.10.46 'sleep 50 &amp; echo $!') ; echo $pid
  2135
  # Killed by signal 2.
  ^C
  #
  </code></pre>
  
  <p>I need this for a script, so I'd like to know why <code>CTRL-c</code> is needed and is it possible to work around it?</p>
  
  <p><strong>Update</strong></p>
  
  <p>It looks like it opens an extra Bash shell, and that is the one that needs to be exited.</p>
  
  <p>The command I am actually interesting in is</p>
  
  <pre><code>read -r pid &lt; &lt;(ssh 10.10.10.46 "mbuffer -4 -v 0 -q -I 8023 &gt; /tmp/mtest &amp; echo $!"); echo $pid
  </code></pre>