Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "comment-out" (add comment) in a batch/cmd?

I have a batch file that runs several python scripts that do table modifications.

  1. I want to have users comment out the 1-2 python scripts that they don't want to run, rather than removing them from the batch file (so the next user knows these scripts exist as options!)

  2. I also want to add comments to bring to their attention specifically the variables they need to update in the Batch file before they run it. I see that I can use REM. But it looks like that's more for updating the user with progress after they've run it.

Is there a syntax for more appropriately adding a comment?

like image 349
user1397044 Avatar asked Jun 29 '12 21:06

user1397044


People also ask

How do you comment out in CMD?

You can use :: or rem for comments. Only if comments are in if , use rem , as the colons could make errors, because they are a label.

What command comments out a line in a batch file?

Comments Using the :: Statement The other way to create comments in Batch Script is via the :: command. Any text which follows the :: statement will be treated as comments and will not be executed.

What is %% in a batch file?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

What is @echo off in batch script?

batch-file Echo @Echo off @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.


1 Answers

Use :: or REM

::   commenttttttttttt REM  commenttttttttttt 

BUT (as people noted):

  • :: doesn't work inline; add & character:
    your commands here & :: commenttttttttttt
  • Inside nested parts (IF/ELSE, FOR loops, etc...) :: should be followed with normal line, otherwise it gives error (use REM there).
  • :: may also fail within setlocal ENABLEDELAYEDEXPANSION
like image 94
T.Todua Avatar answered Sep 18 '22 13:09

T.Todua