In Bash, # is used to comment the following. How do I make a comment on the Windows command line?
-
1Possible duplicate of [Which comment style should I use in batch files?](http://stackoverflow.com/questions/12407800/which-comment-style-should-i-use-in-batch-files) – Michael Freidgeim Jan 27 '16 at 01:30
-
For block comments see http://stackoverflow.com/questions/8526946/commenting-multiple-lines-in-dos-batch-file – AjV Jsy Apr 01 '16 at 08:49
-
Possible duplicate of [How to "comment-out" (add comment) in a batch/cmd?](https://stackoverflow.com/questions/11269338/how-to-comment-out-add-comment-in-a-batch-cmd) – jonrsharpe Jan 14 '19 at 20:04
8 Answers
The command you're looking for is rem
, short for "remark".
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 :-)
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
)
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, the first line below outputs all hello rem a comment
but the second outputs the single word hello
:
echo hello rem a comment.
echo hello& rem a comment.
The second is two separate commands separated by &
, and with no spaces before the &
because echo will output those as well. That's not necessarily important for screen output but, if you're redirecting to a file, it may:
echo hello >file - includes the space.
echo hello>file - no space.

- 854,327
- 234
- 1,573
- 1,953
-
5I knew of REM but was not aware of the `::` syntax. Is it not widely known? – JAB Jun 08 '10 at 15:35
-
7Well, I know there's one person that knew of it. And now there's two :-) Maybe I can claim that I doubled the amount of knowledge in the world. FWIW, Rob van der Woude's site is a truly excellent one for batch file (and other) chicanery: http://www.robvanderwoude.com/batchfiles.php – paxdiablo Jun 08 '10 at 23:55
-
1[Which comment style should I use in batch files?](http://stackoverflow.com/q/12407800/395857) gives more details about `::`. – Franck Dernoncourt Feb 23 '16 at 01:50
-
1To avoid the comment from appearing in the output you can prefix `REM` with an `@`: `@REM Some comment` – Marcono1234 Jul 06 '21 at 15:20
-
@david-rogers [answer](https://stackoverflow.com/a/29853831/5478086) seems more appropriate since it allows comments in the command line. – Herman Autore Jul 21 '22 at 15:24
-
@Herman: Though I already had the use of `&` in the answer (as `rem` is a command), I've expanded on the explanation. – paxdiablo Jul 21 '22 at 23:33
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.

- 4,010
- 3
- 29
- 28
A comment is produced using the REM command which is short for "Remark".
REM Comment here...

- 100,552
- 23
- 116
- 167
It's "REM".
Example:
REM This is a comment

- 30,738
- 21
- 105
- 131

- 7,736
- 11
- 45
- 60
: this is one way to comment
As a result:
:: this will also work
:; so will this
:! and this
: ***** and so on ***** :
: // even this \\ :
Above styles work outside codeblocks, otherwise:
REM is another way to comment.

- 2,854
- 18
- 26
Lines starting with "rem" (from the word remarks) are comments:
rem comment here
echo "hello"

- 24,152
- 13
- 73
- 111
Powershell
For powershell, use #
:
PS C:\> echo foo # This is a comment
foo

- 40,825
- 36
- 187
- 242
A single colon without a space after it is enough
Just don't leave comments at the last line in block
Finally, this works:
if 1==1 (
:comment line 1
echo 1 equals 1
)

- 526
- 5
- 8