tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here.

I have following script (called out_to_streams.csh):

#!/bin/tcsh -f

echo Redirected to STDOUT > /dev/stdout
echo Redirected to STDERR > /dev/stderr

echo Should default to STDOUT without redirection

When I pipe the output like this:

./out_to_streams.csh | vim -

I get "Redirect to STDOUT" and "Should default to STDOUT without redirection" being piped.

When I redirect to a file:

./out_to_streams.csh > mystdout
  • the shell shows "Redirected to STDERR" as expected
  • mystdout only contains "Should default to STDOUT without redirection"
  • "Redirected to STDOUT" is totally missing

Anyone can explain what happens to "Redirected to STDOUT"?

The first line "Redirected to STDOUT" which you expect to show up in the file mystdout got overwritten by the last one "Should default to STDOUT without redirection"...and this will happen with any sh not just the tcsh...and by appending to mystdout you will see both the lines there...

./out_to_streams.csh >> mystdout

Tried it and I get the same result. I've tried "append redirect" (i.e. ">>") on the command line as suggested, and it did not work. I changed it in the script as well:

#!/bin/tcsh -f

echo Redirected to STDOUT >> /dev/stdout
echo Redirected to STDERR >> /dev/stderr

echo Should default to STDOUT without redirection

And "Redirect to STDOUT" still gets lost. I've tried all four combinations (i.e. ">" vs ">>" in script and on command line), and in all cases "Redirect to STDOUT" gets lost.

Is there some bizarre handling of the IO streams and redirects in tcsh that can explain this behavior?