title: Bash: echo a variable containing program output, to a file
body: <p>When I execute <strong>unison tours 2> /dev/null | grep -A 2 '&lt;-?->'</strong> on a bash prompt, I get the exact output i'm looking for:</p>
  
  <pre><code>*changed  &lt;-?-&gt; changed    Future Tours/File Clash Test.docx  
  local        : changed file       modified on 2013-06-05 at 16:24:40  size 10221     rw-rw----  
  bj-server... : changed file       modified on 2013-06-05 at 16:23:53  size 10232     rw-rw----*
  </code></pre>
  
  <p>When I put this into a shell script: </p>
  
  <pre><code>#!/bin/bash
  tmp=$(unison tours 2&gt; /dev/null | grep -A 2 '&lt;-?-&gt;')
  echo "$tmp" &gt; /home/users/itsystem/test.log
  </code></pre>
  
  <p>... it comes out strange. Running <strong>more test.log</strong> , I get the following:</p>
  
  <pre>- Systems Sheets/Feedback She
                                                                  oup).xls
  | Past Tours/2012/CE0
                          12 Cherry (N...our Menus/Lijiang Tour  Menus.xls
  
  - Past Tours/2012/UC041112 St
  - Past Tours/2012/UC081112 Lopata (N... Menus - UC081012 Lo
                  2/VC110912 Levin (VI... Menus - VC110912 Levin (VI).xlsx
                                                                      xlsx
  | Future Tours/2013 Futur
  / Inquiries/Outstanding/Terence Park... Itinerary (Trev
  changed   changed    Future Tours/File Clash Test.docx
  local        : changed file       modified on 2013-06-05 at 16:24:40  size 10221     rw-rw----
  bj-server... : changed file       modified on 2013-06-05 at 16:23:53  size 10232     rw-rw----</pre>
  
  <p>Where is the other crap coming from?</p>
  
  <p>If you simply run <b>unison</b> then you do get an <em>animated</em> one line of output that is constantly refreshed with a rotating -\|/ showing the working folder, but which eventually disappears.</p>
  
  <p>If my grep works on the bash prompt, why not from the shell script?</p>