|
|
REM
In a batch file
REM signifies a comment or REMARK
adding :: at
the start of a line has a similar effect
For example:
@ECHO OFF
::
:: First comment
::
REM Second comment
REM
::
Although you can use rem without a comment to add vertical spacing to a batch
file, you can also use blank lines. The blank lines are ignored when processing
the batch program.
The double-colon is not documented as a comment command, it is a special case of a CALL label that acts like a comment. The pro's and cons of each method are listed below.
Bugs
There are problems
using a :: comment within an IF or FOR code bracket
e.g.
@echo off
FOR /L %%i IN (1,1,10) Do (
Echo before comment
:: Some comment
Echo after comment
)
The above will return the error :: was unexpected at this time.
In the script below the DIR command will set an %errorlevel%=2
if the file is not found, but the REM command is then executed successfully
and resets
%errorlevel%=0
If you use :: for the comment the errorlevel stays at 2.
DIR nonexistentfile.txt
REM some comment
ECHO %errorlevel%
The problem above was fixed* in Win XP and later service packs of NT 4.
Finally in Windows 2000 and XP a comment like
::%~
or
REM %~ will
be interpreted giving the error:
The following usage of the path operator in batch-parameter substitution is
invalid: %~
The bottom line on this is that you must test your comments to be sure they will be ignored as you expect.
Registry Comments
Within a registry
file comments can be preceded by "; "
e.g.
;
; Turn the NUMLOCK on at login
;
[HKEY_CURRENT_USER\Control Panel\Keyboard]
"InitialKeyboardIndicators"="2"
FTP Comments
There is no valid comment character for FTP but you can cheat
by escaping to the shell and running REM
e.g.
C:\WORK>type ftpscript
!REM This is a remark
bye
C:\WORK>ftp -s:ftpscript
ftp> !REM This is a remark
ftp> bye
C:\WORK>
* The errorlevels set by DIR are different under Windows NT 4 and XP
Equivalent Linux BASH commands:
### - Comment / Remark