title: Bourne shell: Force STDOUT to STDERR
body: <p>I am creating a Subversion <a href="http://svnbook.red-bean.com/en/1.6/svn-book.html#svn.ref.reposhooks.post-commit" rel="nofollow noreferrer">post-commit hook</a>. I need to force the output of one command to STDERR, so that the post-commit hook will marshal the message back to the client.</p>
  
  <p>How can I force STDOUT to STDERR?</p>
  
  <p>In this simplified example, the file <code>foo</code> exists, but <code>bar</code> does not.</p>
  
  <pre><code># touch foo
  # ls foo bar
  ls: bar: No such file or directory
  foo
  </code></pre>
  
  <p>I want to send STDOUT to STDERR. I assumed that I could do this with <code>&gt;&amp;2</code>, but it doesn't seem to be working.</p>
  
  <p>I was expecting following example to redirect STDOUT to STDERR, and that <code>/tmp/test</code> would would contain the output and error for the command. But instead, it appears that STDOUT is never redirected to STDERR, and thus <code>/tmp/test</code> only contains the error from the command.</p>
  
  <pre><code># ls foo bar &gt;&amp;2 2&gt;/tmp/test
  foo
  # cat /tmp/test
  ls: bar: No such file or directory
  </code></pre>
  
  <p>What am I missing?</p>
  
  <p>I have tried the above example on CentOS, Ubuntu, FreeBSD and MacOSX.</p>