title: Empty file when transferring files using nc
body: <p>I am struggling long time on the weird situation on file transferring using nc, I use the following bash script to transfer files from A machine to B machine, the script seems okay and the file is being transfer to the B machine, however the file's size is 0 byte and does not have any contents (which it really contains in machine A), then I run my script second time and this time machine B does contain content, may I know which part my script cause this problem? Million thanks for the help!</p>
  
  <pre><code>#!/bin/bash
  IPADDRSTR="$1"
  COUNT=0
  for x in $IPADDRSTR
  do
  #server
      IPERRSTR[$COUNT]=$(sshpass -p pass ssh -o StrictHostKeyChecking=no -p 22 root@$x '$(/usr/bin/nc -l -p1234 &gt; /root/a.txt)&amp;' &gt; /dev/null 2&gt;&amp;1 | echo -n $?)
  
          if [ ${IPERRSTR[COUNT]} -eq "0" ]
          then
              nc $x 1234 &lt; ./a.txt
              echo "done"
          fi
      COUNT=$((COUNT+1))
  done
  </code></pre>