title: ssh bash -c exit status does not propagate
body: <p>According to <code>man ssh</code> and <a href="https://stackoverflow.com/questions/15390978/shell-script-ssh-command-exit-status">this previous answer</a>, ssh should propagate the exit status of whatever process it ran on the remote server. I seem to have found a mystifying exception!</p>
  
  <pre><code>$ ssh myserver exit 34 ; echo $?
  34
  </code></pre>
  
  <p>Good...</p>
  
  <pre><code>$ ssh myserver 'exit 34' ; echo $?
  34
  </code></pre>
  
  <p>Good...</p>
  
  <pre><code>$ ssh myserver bash -c 'exit 34' ; echo $?
  0
  </code></pre>
  
  <p>What?!?</p>
  
  <pre><code>$ ssh myserver
  ubuntu@myserver $ bash -c 'exit 34' ; echo $?
  34
  </code></pre>
  
  <p>So the problem does not appear to be either ssh or <code>bash -c</code> in isolation, but their combination does not behave as I would expect.</p>
  
  <p>I'm designing a script to be run on a remote machine that needs to take an argument list that's computed on the client side. For the sake of argument, let's say it fails if any of the arguments is not a file on the remote server:</p>
  
  <pre><code>ssh myserver bash -c '
      for arg ; do
          if [[ ! -f "$arg" ]] ; then
              exit 1
          fi
      done
  ' arg1 arg2 ...
  </code></pre>
  
  <p>How can I run something like this and effectively inspect its return status? The test above seems to suggest I cannot.</p>