How do I comment on the Windows command line?

2020-02-16 20:13发布

In Bash, # is used to comment the following. How do I make a comment on the Windows command line?

6条回答
混吃等死
2楼-- · 2020-02-16 20:51

A comment is produced using the REM command which is short for "Remark".

REM Comment here...
查看更多
孤傲高冷的网名
3楼-- · 2020-02-16 20:53
: this is one way to comment
REM is another way to comment.

As a result:

:: this will also work
:; so will this
:! and this
查看更多
何必那么认真
4楼-- · 2020-02-16 20:58

It's "REM".

Example:

REM This is a comment
查看更多
乱世女痞
5楼-- · 2020-02-16 21:04

The command you're looking for is 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.

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.

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.
查看更多
等我变得足够好
6楼-- · 2020-02-16 21:07

Lines starting with "rem" (from the word remarks) are comments:

rem comment here
echo "hello"
查看更多
爷、活的狠高调
7楼-- · 2020-02-16 21:14

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 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.

查看更多
登录 后发表回答