In some cases, we need to use a large segment of comments in batches, that is, more than 2 lines of consecutive comments. So, how do you achieve him?
There are a number of ways to do this, and this article only lists some of them.
㈠, using REM
Note: You cannot use redirects and pipe breaks in comments;
When Echo is on, the REM command and comment content will be displayed;
There are spaces between REM and annotations.
| Example: |
REM Note Content 1 REM Note Content 2 REM Note Content 3 |
㈡, using::
Windows XP can recognize a colon (:) The batch program line that starts as a label and does not process it as a command. If a line starts with a colon, any command for that row is ignored.
| Example: |
:: note Content 1 :: Note Content 2 :: note Content 3 |
㈢, using echo >nul
Note: You cannot use redirects and pipe breaks in comments;
There is a space between the Echo and the comment.
| Example: |
Echo Comment Content 1>nul Echo Comment Content 2>nul Echo Comment Content 3>nul |
㈣, using goto
Note: You cannot use goto-pointing labels in comments
| Example: |
Goto Han Note Content 1 Note Content 2 Note Content 3 : Han |
㈤, using: Notes
Note: the first character in the note cannot be a number or a letter;
| Example: |
: note Content 1 : Note Content 2 : note Content 3 |
Description: in actual use, for example tag: STSRT, we can also think of him as a comment. The following example:
:: Argparse.bat-parser of command line arguments :: Would sort-2005-11-26-winxp_cmd/msdos7.10/msdos6.22 @echo off
: Init For%%e in (directory_i directory_o filter_f filter_v log) do set%%e=
:P Arseloop If "%1" = = "" Goto Start For%%s in (I-f f v l o O) do if "%1" = = "/%%s" gotoswitch%%s echo error:invalid switch '%1 '! Goto Quit
: Switchi If "%directory_i%" = = "" Set directory_i=%2 Goto Nextarg
: Switcho If "%directory_o%" = = "" Set directory_o=%2 Goto Nextarg
: SWITCHF If "%filter_f%" = = "" Set filter_f=%2 Goto Nextarg
: SWITCHV If "%filter_v%" = = "" Set filter_v=%2 Goto Nextarg
: Switchl If "%log%" = = "" Set log=%2 Goto Nextarg
: Nextarg Shift Shift Goto Parseloop
: Start Echo.directory_i%directory_i% Echo.directory_o%directory_o% Echo.filter_f%filter_f% Echo.filter_v%filter_v% Echo.log%log%
: Quit For%%e in (directory_i directory_o filter_f filter_v log) do set%%e= : End |
㈥, using: Label annotations
| Example: |
: Han Note: The following code ... Command 1 Command 2 |
㈦, using if not exist nul comment
Note: You cannot use redirects and pipe breaks in comments;
There should be a space between the if not exist nul and the comment.
| Example: |
If not exist nul note content 1 If not exist nul note content 2 If not exist nul note content 3 |
Multiple annotation methods in batch processing