-3

I have recently learned a method of commenting in batch file in style of any language. It is:

<nul set /p="=" # Powershell or python style
<nul set /p="=" // Java script style

Here the = is omitted and the line is fully ignored. Here any explanation is appreciated.

Thank you!

programmer365
  • 12,641
  • 3
  • 7
  • 28
  • Your question make absolutely no sense to me. Why have you posted two [tag:windows] [tag:cmd]/[tag:batch-file] lines and included commenting for two completely different programming languages? cmd.exe uses a case insensitive `rem` to prepend remarks/comments, _although sometimes people use a broken label identifier as well, `::`_. The best way, I've seen for commenting is that originally championed by Dave Benham, which uses undefined variables for comments. – Compo Jan 01 '20 at 16:00
  • Thank you @Compo for your reply. I wanted to just know the explanation. Also it was the style of commenting of another language and no need of the consultation of the expert of those languages so I didn't feel the necessity to add those tags. – programmer365 Jan 01 '20 at 16:14
  • I forgot to provide an example for you, Wasif Hasan, [here's one](https://stackoverflow.com/a/28698386), and some possibly related questions too, [here](https://stackoverflow.com/q/8526946), and [here](https://stackoverflow.com/q/12407800). I hope you find them useful. – Compo Jan 01 '20 at 16:21

1 Answers1

4

This uses the extended syntax of the SET command.

set "varname=content"

The quotes are before the varname and at the end of the content, this avoids in unintended white spaces, as anything after the last quote is dropped.

As long as there are no quotes, ampersands or pipes after the last quote, it's can be used for comments.

Your example <nul set /p="=" causes a syntax error, because it starts with an equal sign.
It should be <nul set /p"=", then it works as expected.

The <nul set /p syntax can be used to output text without a line feed. But in this case, nothing will be printed, as there is only a single equal sign without any text to output.

jeb
  • 70,992
  • 15
  • 159
  • 202
  • Well, `set /p="="` causes a syntax error on my Windows 10 machine, but `set /p "="` would work, of course... – aschipfl Jan 02 '20 at 06:55
  • @aschipfl Thanks, you are right. I should have tested it before. I edited my answer – jeb Jan 02 '20 at 07:26