This is an obscene effect in batch code blocks.
In a code block, a label on one line always requires a secondary line with completely different syntax rules (for a secondary line).
SO: goto command not working
The secondary line must be a command or a simple label, but not a bracket, nor a double colon, nor an internal command attached to the bracket.
MC ND explained that : used here as a regular drive letter, it really is! But only in the secondary line, and even you can suppress the error with subst :: C:\ , the line is treated as a label (you cannot run anything).
subst :: C:\ ( :label ::\windows\system32\calc.exe )
And the second line accepts & , even if the line is a label.
Bad samples
( :Label at the end fails ) ( :label ( echo new Block fails ) echo ... ) ( :label :: Double colon fails ) ( :label echo( fails also, as now a file named "echo(" is searched for execution )
And now working
( ::Works :with a "normal" label in the second line ) ( :But this label! & echo This will not echo'd :but & echo You can see this ! ) ( :label echo or a simple command works too )
As sometimes :: used as one comment style , this can cause problems inside the blocks if you do not need a secondary line.
Edit: answer the second question
What are the rules for determining whether :: means "the beginning of a comment" or "a colon of letters"?
The first :: always a comment or label, and the next line is always a drive letter colon .
jeb
source share