title: remote ssh command: first echo output is lost
body: <p>I'm trying to run several commands on a remote box via ssh 1-liner call by specifying them as semicolon-separated string passed to "bash -c". It works for some cases, but does not for others. Check this out:</p>
  
  <pre><code># Note: the "echo 1" output is lost:
  bash-3.2$ ssh sandbox bash -c "echo 1; echo 2; echo 3"
  
  2
  3
  
  # Note: first echo is ignored again
  bash-3.2$ ssh sandbox bash -c "echo 0; echo 1; echo 2; echo 3"
  
  1
  2
  3
  
  # But when we run other commands (for example "date") then nothing is lost
  bash-3.2$ ssh sandbox bash -c "date; date;"
  Wed Nov  7 20:27:55 UTC 3018
  Wed Nov  7 20:27:55 UTC 3018
  </code></pre>
  
  <p>What am I missing?</p>
  
  <p>Remote OS: Ubuntu 16.04.5 LTS<br>
  Remote ssh: OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g  1 Mar 2016<br>
  <br>
  Local OS: macOS High Sierra Versoin 10.13.3<br>
  Local ssh: OpenSSH_7.6p1, LibreSSL 2.6.2<br></p>
  
  <p>Update:
  The above example is heavily simplified picture of what I'm trying to do.
  The practical application is actually to generate few files on remote box by echo'ing into remote filesystem:</p>
  
  <pre><code>#!/bin/bash
  
  A=a
  B=b
  C=c
  
  ssh -i ~/.ssh/${REMOTE_FQDN}.pem ${REMOTE_FQDN} sudo bash -c \
    "echo $A &gt; /tmp/_a; echo $B &gt; /tmp/_b; echo $C &gt; /tmp/_c;"
  </code></pre>
  
  <p>After I run the above script and go to remote box to check results I see the following:</p>
  
  <pre><code>root@sandbox:/tmp# for i in `find ./ -name '_*'|sort`; do echo "----- ${i} ----"; cat $i; done
  ----- ./_a ----
  
  ----- ./_b ----
  b
  ----- ./_c ----
  c
  </code></pre>
  
  <p>As you can see the 1st "echo" command generated blank file!</p>