title: Capture stdout to a variable but still display it in the console
body: <p>I have a bash script which calls several long-running processes.  I want to capture the output of those calls into variables for processing reasons.  However, because these are long running processes, I would like the output of the rsync calls to be displayed in the console in <em>real-time</em> and not after the fact.</p>
  
  <p>To this end, I have <a href="http://sebthom.de/158-bash-capturing-stderr-variable/">found</a> a way of doing it but it relies on outputting the text to /dev/stderr.  I feel that outputting to /dev/stderr is not a good way of doing things.</p>
  
  <pre><code>VAR1=$(for i in {1..5}; do sleep 1; echo $i; done | tee /dev/stderr)
  
  VAR2=$(rsync -r -t --out-format='%n%L' --delete -s /path/source1/ /path/target1 | tee /dev/stderr)
  
  VAR3=$(rsync -r -t --out-format='%n%L' --delete -s /path/source2/ /path/target2 | tee /dev/stderr)
  </code></pre>
  
  <p>In the example above, I am calling rsync a few times and I want to see the file names as they are processed, but in the end I still want the output in a variable because I will be parsing it later.</p>
  
  <p>Is there a 'cleaner' way of accomplishing this? </p>
  
  <p>If it makes a difference, I am using Ubuntu 12.04, bash 4.2.24.</p>