Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commenting multiple lines in DOS batch file

I have written huge MS DOS Batch file. To test this batch file I need to execute some lines only and want to hide/comment out remaining.

I have some existing comment lines starting with :: hence I cannot use :: anymore as it will scramble all comments.

How can I solve this problem?

like image 564
user219628 Avatar asked Dec 15 '11 21:12

user219628


People also ask

Can you comment out lines in a batch file?

The batch language doesn't have comment blocks, though there are ways to accomplish the effect. You can use GOTO Label and :Label for making block comments. Or, If the comment block appears at the end of the batch file, you can write EXIT at end of code and then any number of comments for your understanding.

How do I comment a line in DOS batch file?

A batch file can be commented using either two colons :: or a REM command. The main difference is that the lines commented out using the REM command will be displayed during execution of the batch file (can be avoided by setting @echo off ) while the lines commented out using :: , won't be printed.

How do you comment in DOS?

During execution of a batch file, DOS will display (but not act on) comments which are entered on the line after the REM command. You cannot use separators in the comment except the space, tab, and comma. To keep DOS from interpreting commands in a comment line, enclose the command in quotes.


2 Answers

You can use a goto to skip over code.

goto comment ...skip this... :comment 
like image 88
pdubs Avatar answered Sep 25 '22 13:09

pdubs


If you want to add REM at the beginning of each line instead of using GOTO, you can use Notepad++ to do this easily following these steps:

  1. Select the block of lines
  2. hit Ctrl-Q

Repeat steps to uncomment

like image 23
cvacca Avatar answered Sep 25 '22 13:09

cvacca