Migrated From JP Software Wiki
This article describes "quick and dirty" methods of commenting batch files.
Colons
Batch file line labels begin with a colon. If the colon is followed by two spaces, the command processor simply ignores the entire line. It is not treated as a line label and it also does not generate a syntax error.
Text -- Endtext block
A large "comment block" can be inserted between TEXT -- ENDTEXT commands that are never called. In the example one block is skipped with GOTO and the other is after a subroutine. The reason TEXT -- ENDTEXT is necessary is because if you just use GOTO the command processor may interpret the comment text as command lines and generate a syntax error.
An advantage to this method is that if you need printed instructions you can put them in the TEXT -- ENDTEXT block and to display them copy the file and simply make the first line of the copy GOTO LONG_COMMENT. Note that the Pause and Quit are inside the comment although after the ENDTEXT, so in normal operation they have no effect.
Alternatively, you could make the first or second line IF "%1"=="comments" GOTO LONG_COMMENT. (Note: All the double quotes are necessary and there are two equal signs, not one.) If you want to display the LONG_COMMENT section only, you run the batch file with the command-line parameter "comments".
This article describes "quick and dirty" methods of commenting batch files.
Colons
Batch file line labels begin with a colon. If the colon is followed by two spaces, the command processor simply ignores the entire line. It is not treated as a line label and it also does not generate a syntax error.
Code:
: To create a neat comment block quickly, simply
: begin each line with a colon followed by at least
: two spaces.
: As usual, blank lines won't cause a problem.
Text -- Endtext block
A large "comment block" can be inserted between TEXT -- ENDTEXT commands that are never called. In the example one block is skipped with GOTO and the other is after a subroutine. The reason TEXT -- ENDTEXT is necessary is because if you just use GOTO the command processor may interpret the comment text as command lines and generate a syntax error.
An advantage to this method is that if you need printed instructions you can put them in the TEXT -- ENDTEXT block and to display them copy the file and simply make the first line of the copy GOTO LONG_COMMENT. Note that the Pause and Quit are inside the comment although after the ENDTEXT, so in normal operation they have no effect.
Alternatively, you could make the first or second line IF "%1"=="comments" GOTO LONG_COMMENT. (Note: All the double quotes are necessary and there are two equal signs, not one.) If you want to display the LONG_COMMENT section only, you run the batch file with the command-line parameter "comments".
Code:
IF SOMETHING (WHATEVER)
GOSUB SOME_SUB
GOTO AFTER_COMMENT
:LONG_COMMENT
TEXT
Whatever you want here.
ENDTEXT
PAUSE
QUIT
:AFTER_COMMENT
ECHO SOMETHING
RETURN (or QUIT or EXIT)
:SOME_SUB
(subroutine code)
RETURN
TEXT
Whatever you want here as "comments".
ENDTEXT