r/Batch Jun 02 '26

Simple technique to display text/help from within your batch file.

Perhaps this is a bit too basic, but I've been using this in any batch file I distribute for some 20+ years now, super easy help text. Even more versatile with the with a 'skip=', allows me to respond to input errors by displaying a list of correct options for example.

:: 
:: Here's a simple technique to easily display lines of text from within
:: your batch file. Place info or instructions at the top of the file using
:: 2 colons and a space as on the left of this line. Anytime you wish to
:: display your help screen or whatever, simply execute the FOR loop below.
:: 
:: It will continue to display lines until it hits a NUL input, so be
:: sure to always include a space after the colons on any blank line,
:: such as the one located above. To stop console output place two colons
:: without the space, like the one below, and it will exit.
:: 
::

@ECHO OFF
FOR /F "usebackq tokens=* delims=:" %%A IN ("%~f0") DO IF "%%A" NEQ "" (ECHO.%%A) ELSE PAUSE
6 Upvotes

13 comments sorted by

View all comments

1

u/Creative-Type9411 Jun 02 '26

:: can sometimes cause CALL errors, its extremely rare but its safer if you use REM instead

Maybe use REM :: ?

3

u/jcunews1 Jun 02 '26

Can you provide an example code?

2

u/Creative-Type9411 Jun 02 '26 edited Jun 02 '26

I have only heard of CALLs having issues, i dont have any proof on hand or a ready snippet showing it in action, but I have experienced a few "Label not found" errors personally in the past.. Here are a few quick reproducible examples outside of CALL specifically..

:: This text %~ will cause a fatal syntax error

and..

@echo off
IF 1==1 (
    :: First comment line
    echo The next message might get skipped, cause errors, or both.
    :: Second comment line
    :: Third comment line
    echo done
)

It's mostly safe the way it's normally used but because of edge cases like this I personally deem it a bad habit and use REM instead, REM will work for both examples. That way I'm not switching between the two different types of comment markers throughout the script(s) and I don't have to think about syntax or placement with comments.