CMD Master
Back to Blog
Arnošt Havelka

Create Your First Commented Batch File

Write a real .bat script with REM comments using the built-in code editor.

Start Interactive Lesson
Create Your First Commented Batch File

Create Your First Commented Batch File

Now that you know how to open files in a text editor, let's write a real batch file with comments. Comments keep your scripts readable and maintainable. We'll use the editor below to write directly in your browser.

Usage:@REM
[your comment]
@REM
Adds a comment. The @ prevents the line from being echoed to the screen.
@echo off
Hides command clutter — always put this first in a batch file.
echo
Prints a message to the console.

Write Your Script in the Editor

Use the editor below to write a batch file with REM comments. Click ▶ Run to simulate the output, then ⬇ Download .bat to save and run it in a real terminal.

myscript.bat.bat

Notice: The @REM lines do not appear in the output — they are invisible comments. Only the echo lines produce output.

Why Comments Matter

As your scripts grow longer, comments become essential:

@echo off
@REM # ==============================
@REM # backup.bat  —  Daily Backup
@REM # Run every morning at 8:00 AM
@REM # ==============================

@REM # Step 1: Set source and destination
SET SRC=C:\Users\Me\Documents
SET DST=D:\Backup\Documents

@REM # Step 2: Run the copy
echo Backing up %SRC% to %DST%...
xcopy %SRC% %DST% /s /y /q

@REM # Step 3: Confirm
echo Done! Backup complete.
PAUSE

Good comments answer:


Knowledge Check

1 / 4

What is the first line you should put in most batch files?

Up Next

Introduction to Batch Files

Automate your daily tasks.