uid0, on 24 February 2012 - 07:57 AM, said:
I guess it's because 0 has a special meaning, like 1 and 2 are stdout and stderr.
Jaclaz, any idea what 0 means?
No, I guess that is one of the "quirks" of batch/command line parsing, if you try:
echo mytest=3>>mytest.txt
or:
echo mytest=9>>mytest.txt
the behaviour is the same,
BUT if you try:
echo mytest=1>>mytest.txt
(which is the redirection you suspect, the result is "mytest=" echoed to the file, using 2 works like the other bigger numbers and 0, but in the case of 2, as well as of 1 it is the "expected behaviour")
AND if you try:
echo mytest=10>>mytest.txt
or:
echo mytest=d>>mytest.txt
everything reverts to "normal".
So it is seemingly something that happens:
- with numbers only
- with a single number only
- with number 0 and numbers 3÷9 only (the behaviour with 1 and 2 is "as expected")
The same issue happens also if you put (.ini style) a space on both sides of the = sign:
echo mytest = 0>>mytest.txt
Try running this:
@ECHO OFF
IF EXIST mytest.txt DEL mytest.txt
ECHO mytest=0>>mytest.txt
ECHO 0&TYPE mytest.txt&PAUSE
ECHO mytest=1>>mytest.txt
ECHO 1&TYPE mytest.txt&PAUSE
ECHO mytest=2>>mytest.txt
ECHO 2&TYPE mytest.txt&PAUSE
ECHO mytest=3>>mytest.txt
ECHO 3&TYPE mytest.txt&PAUSE
ECHO mytest=4>>mytest.txt
ECHO 4&TYPE mytest.txt&PAUSE
ECHO mytest=5>>mytest.txt
ECHO 5&TYPE mytest.txt&PAUSE
ECHO mytest=6>>mytest.txt
ECHO 6&TYPE mytest.txt&PAUSE
ECHO mytest=7>>mytest.txt
ECHO 7&TYPE mytest.txt&PAUSE
ECHO mytest=8>>mytest.txt
ECHO 8&TYPE mytest.txt&PAUSE
ECHO mytest=9>>mytest.txt
ECHO 9&TYPE mytest.txt&PAUSE
ECHO mytest=10>>mytest.txt
ECHO 10&TYPE mytest.txt&PAUSE
ECHO mytest=11>>mytest.txt
ECHO 11&TYPE mytest.txt&PAUSE
And watch attentively the behaviour.
EDIT:
Nice different behaviour also with DELAYEDEXPANSION:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET zero=0
SET one=1
SET two=2
SET three=3
ECHO with "%%"
IF EXIST mytest.txt DEL mytest.txt
ECHO mytest=%zero%>>mytest.txt
ECHO 0&TYPE mytest.txt
ECHO mytest=%one%>>mytest.txt
ECHO 1&TYPE mytest.txt
ECHO mytest=%two%>>mytest.txt
ECHO 2&TYPE mytest.txt
ECHO mytest=%three%>>mytest.txt
ECHO 3&TYPE mytest.txt
PAUSE
ECHO Now with "^!"
IF EXIST mytest.txt DEL mytest.txt
ECHO mytest=!zero!>>mytest.txt
ECHO 0&TYPE mytest.txt
ECHO mytest=!one!>>mytest.txt
ECHO 1&TYPE mytest.txt
ECHO mytest=!two!>>mytest.txt
ECHO 2&TYPE mytest.txt
ECHO mytest=!three!>>mytest.txt
ECHO 3&TYPE mytest.txt
PAUSE
jaclaz
This post has been edited by jaclaz: 24 February 2012 - 11:29 AM