How to echo "2" (no quotes) to a file, from a batch script?

user541686 picture user541686 · Aug 29, 2011 · Viewed 31.9k times · Source

How do I echo the number 2 into a file, from a batch script?

This doesn't work:

Echo 2>> file.txt

because 2>> is a special command. :(

Answer

Raymond Chen picture Raymond Chen · Aug 29, 2011

Little-known feature: The redirection operator can go anywhere on the line.

>>file.txt echo 2