title: Why does redirecting output affect the result of a test in bash?
body: <p>I'm trying to write a script to launch xfce and xbmc in their own x sessions.</p>
  
  <p>To do this I'm setting the <code>DISPLAY</code> value, running the first one in the background and waiting until I get a successful return from <code>xset q</code>. Then I change <code>DISPLAY</code> and do the same for the other.</p>
  
  <p>I'm writing this piece by piece to check I've got the syntax right for each part and the part I'm stuck on is the 'waiting until I get a successful return from <code>xset q</code>.</p>
  
  <pre><code>export DISPLAY=":0.0"
  while [[ ! `xset q` ]]
  do
    echo -n "."
  done
  </code></pre>
  
  <p>This code seems to work so when XFCE is running it exits immediately and when it is not it sits there printing <code>.xset: unable to open display ":0.0"</code></p>
  
  <p>However I don't want to see the output of <code>xset</code> so I'm trying to redirect its output.</p>
  
  <pre><code>export DISPLAY=":0.0"
  while [[ ! `xset q &gt; /dev/null 2&gt;&amp;1` ]]
  do
    echo -n "."
  done
  </code></pre>
  
  <p>Adding this redirection however seems to break the detection, and regardless of whether XFCE is running or not it just sits there printing dots.</p>
  
  <p>I've tested the two commands on their own and in a shell script on their own they both work as I expect, returning 1 when XFCE is not running and 0 when it is.</p>
  
  <p>Can anyone explain why putting that command inside of <code>[[ ! &#96;&#8230;&#96; ]]</code> breaks the <code>while</code> test and how I could rewrite this <code>while</code> loop correctly?</p>
  
  <p>(Running on Arch)</p>