title: SSH Remote command exit code
body: <p>I know there are lots of discussions about it but i need you help with ssh remote command exit codes. I have that code:
  (<code>scan</code> is a script which scans for viruses in the given file)</p>
  
  <pre><code>for i in $FILES 
  do
      RET_CODE=$(ssh $SSH_OPT $HOST "scan $i; echo $?")
      if [ $? -eq 0 ]; then
          SOME_CODE
  </code></pre>
  
  <p>The scan works and it returns either 0 or (1 for errors) or 2 if a virus is found. But somehow my return code is always 0. Even, if i scan a virus.</p>
  
  <p>Here is <code>set -x</code> output:</p>
  
  <pre><code>++ ssh -i /home/USER/.ssh/id host 'scan Downloads/eicar.com; echo 0'
  + RET_CODE='File Downloads/eicar.com: VIRUS: Virus found.
      code of the Eicar-Test-Signature virus
  0'
  </code></pre>
  
  <p>Here is the Output if i run those commands on the "remote" machine without ssh:</p>
  
  <pre><code>[user@ws ~]$ scan eicar.com; echo $?
  File eicar.com: VIRUS: Virus found.
      code of the Eicar-Test-Signature virus
  2
  </code></pre>
  
  <p>I just want to have the return Code, i dont need all the other output of <code>scan</code>.</p>
  
  <p>!UPDATE!</p>
  
  <p>It seems like, <code>echo</code> is the problem.</p>