I’ve been writing some batch files, and I ran into this user guide, which has been quite informative. One thing it showed me was that lines can be commented not just with REM, but also with ::. It says:
Comments in batch code can be made by using a double-colon, this is better than using the REM command because labels are processed before redirection symbols.
::<remark>causes no problems butrem <remark>produces errors.
Why then, do most guides and examples I see use the REM command? Does :: work on all versions of Windows?
tl;dr:
REMis the documented and supported way to embed comments in batch files.::is essentially a blank label that can never be jumped to, whereasREMis an actual command that just does nothing. In neither case (at least on Windows 7) does the presence of redirection operators cause a problem.However,
::is known to misbehave in blocks under certain circumstances, being parsed not as a label but as some sort of drive letter. I’m a little fuzzy on where exactly but that alone is enough to make me useREMexclusively. It’s the documented and supported way to embed comments in batch files whereas::is merely an artifact of a particular implementation.Here is an example where
::produces a problem in aFORloop.This example will not work in a file called
test.baton your desktop:While this example will work as a comment correctly:
The problem appears to be when trying to redirect output into a file. My best guess is that it is interpreting
::as an escaped label called:echo.