I have a batch file that runs several python scripts that do table modifications.
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!)
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?
You can comment something out using
::
orREM
:or
To do it on the same line as a command, you must add an ampersand:
or
Note:
::
in nested logic (IF-ELSE
,FOR
loops, etc...) will cause an error. In those cases, useREM
instead.No, plain old batch files use
REM
as a comment.ECHO
is the command that prints something on the screen.To "comment out" sections of the file you could use
GOTO
. An example of all these commands/techniques:What can I say? batch files are a relic of times long gone, they're clunky and ugly.
You can read more on this website.
EDIT: modified the example a bit to have it contain the elements you are apparently looking for.
::
orREM
BUT (as people noted):
&
character:your commands here & :: commenttttttttttt
IF/ELSE
,FOR
loops, etc...) useREM
because::
gives an error.::
may fail withinsetlocal ENABLEDELAYEDEXPANSION
Putting comments on the same line with commands: use
& :: comment
Explanation:
&
separates two commands, so in this casecolor C
is the first command and:: set red font color
is the second one.Important:
This statement with comment looks intuitively correct:
but it is not a valid use of the comment. It works only because
goto
ignores all arguments past the first one. The proof is easy, thisgoto
will not fail either:But similar attempt
fails executing the command due to 4 arguments unknown to the
color
command:::
,grey
,on
,blue
.It will only work as:
So the ampersand is inevitable.
The
rem
command is indeed for comments. It doesn't inherently update anyone after running the script. Some script authors might use it that way instead ofecho
, though, because by default the batch interpreter will print out each command before it's processed. Sincerem
commands don't do anything, it's safe to print them without side effects. To avoid printing a command, prefix it with@
, or, to apply that setting throughout the program, run@echo off
. (It'secho off
to avoid printing further commands; the@
is to avoid printing that command prior to the echo setting taking effect.)So, in your batch file, you might use this:
The :: instead of REM was preferably used in the days that computers weren't very fast. REM'ed line are read and then ingnored. ::'ed line are ignored all the way. This could speed up your code in "the old days". Further more after a REM you need a space, after :: you don't.
And as said in the first comment: you can add info to any line you feel the need to
As for the skipping of parts. Putting REM in front of every line can be rather time consuming. As mentioned using GOTO to skip parts is an easy way to skip large pieces of code. Be sure to set a :LABEL at the point you want the code to continue.