1

I've noticed that sometimes when I put comments in my batch script, i get the error:

The syntax of the command is incorrect.

Other times, theres no issue. I see no pattern in the cases it works vs the cases it doesn't.

For example:

for /R /D %%d in (.\*) do (

    echo %%d
    :: comment here  <<NO ERROR>>

    for %%f in (%%d\*) do (

        echo %%f
        :: comment here <<ERROR>>
    ) 
)

The top comment causes no problem, the bottom one does. Both are on their own line, exact same text, tabbed, and directly after an echo statement. No problem with the first comment, second causes errors.

why?

kbirk
  • 3,906
  • 7
  • 48
  • 72
  • 1
    well described here: http://www.robvanderwoude.com/comments.php – wmz Oct 26 '12 at 23:14
  • @wmz, that'd be a valid answer – PA. Oct 27 '12 at 09:23
  • @wmz A workaround is described at robvanderwoude, but not the cause why it fails. That can be found at [SO:batch with goto command not working](http://stackoverflow.com/a/4006006/463115) – jeb Oct 28 '12 at 10:33

1 Answers1

2

If you use REM instead of :: it works for you...

Might be a parser error :-)

for /R /D %%d in (.\*) do (

    echo %%d
    REM comment here  <<NO ERROR>>

    for %%f in (%%d\*) do (

        echo %%f
        REM comment here <<ERROR>>
    ) 
)