如何在Windows命令行上发表评论?
在Bash中,#用于注释以下内容。如何在Windows命令行上进行注释?
In Bash, # is used to comment the following. How do I make a comment on the Windows command line?
您要查找的命令是 rem
,是 remark的缩写。
The command you're looking for is rem
, short for "remark".
还有一个简化版本 ::
有些人会使用,如果您斜视一下并斜着看,这种 看起来像#
。我最初更喜欢该变体,因为我是一个 bash
-aholic,但我仍在尝试忘记BASIC的痛苦日子:-)
There is also a shorthand version ::
that some people use, and this sort of looks like #
if you squint a bit and look at it sideways. I originally preferred that variant since I'm a bash
-aholic and I'm still trying to forget the painful days of BASIC :-)
不幸的是,在某些情况下 ::
会塞满命令行处理器(例如在复杂的 if
中或 for
语句),所以现在我通常使用 rem
。无论如何,这都是骇客行为,是在标签基础结构的基础上进行了修饰,使标签基础结构看起来实际上不是注释。例如,在下面的示例中,尝试用 ::
替换 rem
并查看其工作原理:
Unfortunately, there are situations where ::
stuffs up the command line processor (such as within complex if
or for
statements) so I generally use rem
nowadays. In any case, it's a hack, suborning the label infrastructure to make it look like a comment when it really isn't. For example, try replacing rem
with ::
in the following example and see how it works out:
if 1==1 (
rem comment line 1
echo 1 equals 1
rem comment line 2
)
您还应记住, rem
是 command ,所以您不能像在 bash $ c中的
#
这样的行尾敲打它$ c>。它必须去命令会去的地方。例如,这两个中的仅第二个将回显单个单词 hello
:
You should also keep in mind that rem
is a command, so you can't just bang it at the end of a line like the #
in bash
. It has to go where a command would go. For example, only the second of these two will echo the single word hello
:
echo hello rem a comment.
echo hello & rem a comment.