如何在 Windows 命令行上发表评论?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2997578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I comment on the Windows command line?
提问by Tim
In Bash, # is used to comment the following. How do I make a comment on the Windows command line?
在 Bash 中,# 用于注释以下内容。如何在 Windows 命令行上发表评论?
回答by paxdiablo
The command you're looking for is rem
.
您正在寻找的命令是rem
.
There is also a shorthand version ::
, which sort of looks like #
if you squint a bit and look at it sideways :-) I originally preferred the ::
variant since I'm a bash
-aholic and I'm still trying to forget the painful days of BASIC.
还有一个速记版本::
,#
如果你眯着眼睛看它的侧面看起来有点像:-) 我最初更喜欢这个::
变体,因为我是一个bash
-aholic 并且我仍然试图忘记 BASIC 的痛苦日子.
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 looklike a comment when it really isn't.
不幸的是,在某些情况下,::
命令行处理器会被塞满(例如在复杂if
或for
语句中),所以我rem
现在通常使用。在任何情况下,这是一种黑客行为,将标签基础设施转为使用,使其看起来像一条评论,但实际上并非如此。
You should also keep in mind that rem
isa 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
:
您还应该记住,这rem
是一个命令,因此您不能像#
in那样在行的末尾敲击它bash
。它必须去到命令去的地方。例如,只有这两个中的第二个会回显单个单词hello
:
echo hello rem a comment.
echo hello & rem a comment.
回答by Robin Day
A comment is produced using the REM command which is short for "Remark".
使用 REM 命令生成注释,它是“Remark”的缩写。
REM Comment here...
回答by David Rogers
Sometimes, it is convenient to add a comment to a command line. For that, you can use "&REM misc comment text" or, now that I know about it, "&:: misc comment text". For example:
有时,向命令行添加注释很方便。为此,您可以使用“&REM 杂项注释文本”,或者,现在我知道了,“&:: 杂项注释文本”。例如:
REM SET Token="4C6F72656D20697073756D20646F6C6F" &REM This token is for localhost
SET Token="722073697420616D65742C20636F6E73" &REM This token is for production
This makes it easy to keep track of multiple sets of values when doing exploration, tests of concept, etc. This approach works because '&' introduces a new command on the same line.
这使得在进行探索、概念测试等时很容易跟踪多组值。这种方法有效,因为“&”在同一行引入了一个新命令。
回答by masfenix
It's "REM".
是“REM”。
Example:
例子:
REM This is a comment
回答by PeterMmm
Lines starting with "rem" (from the word remarks) are comments:
以“rem”开头的行(来自单词注释)是注释:
rem comment here
echo "hello"
回答by Zimba
: this is one way to comment
As a result:
其结果:
:: this will also work
:; so will this
:! and this
Above styles work outsidecodeblocks, otherwise:
以上样式在代码块之外工作,否则:
REM is another way to comment.