title: writing PID of a command in a variable
body: <p>I have this command launched in a bash script:</p>
  
  <p><code>rsync -av $sourcedir/ $destdir/</code></p>
  
  <p>how do I store the PID for that specific command in a variable in the same script?</p>
  
  <p>i tried with:</p>
  
  <p><code>rsync -av --stats  $sourcedir/ $destdir/ &amp;&amp; pid=$(echo $$)</code></p>
  
  <p>but the pid reported for that operation in the log file differs from the one printed out echoing $pid</p>
  
  <p>thanks for any help!</p>