rem - Comment

Maintained on

If you revisit a batch file later or hand it to someone else, leaving comments that explain the intent of each step makes it much easier to read.

The rem command is the official way to write comments in a Windows batch file.

This article explains the basics of rem, its relationship with @echo off and @rem, and how it differs from the commonly seen ::.

Basics of the rem Command

The basic syntax for a comment is:

rem comment

For example:

@echo off
setlocal

rem Ask the user for a favorite fruit
echo Please enter your favorite fruit.
set /p fruit=Example: apple

endlocal

When you run this batch file, the comment stays in the file as an explanation, and the only messages shown on screen are those printed by echo.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>sample.cmd
Please enter your favorite fruit.
Example: apple

Why Comments Sometimes Appear on Screen

rem does not display comments.

Comments sometimes show up on screen because command echo is on, so the line itself is printed.

setlocal

rem Ask the user for a favorite fruit
echo Please enter your favorite fruit.
set /p fruit=Example: apple

endlocal
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>sample.cmd
C:\Users\user>setlocal
C:\Users\user>rem Ask the user for a favorite fruit
C:\Users\user>echo Please enter your favorite fruit.
Please enter your favorite fruit.
C:\Users\user>set /p fruit=Example: apple
Example: apple
おすすめ書籍※ 広告を含む場合があります
中小企業経営者のためのRPA入門 RPA導入を成功させる方法

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超入門

60分でわかる! AIエージェント 超入門

コマンドラインの黒い画面が怖いんです。

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

The Difference Between @echo off and @rem

@echo off

Putting @echo off at the top of a file stops the following command lines from being displayed. It is the most common way to start a batch file.

@rem

@rem suppresses command echo for that one line only.

setlocal

@rem Ask the user for a favorite fruit
echo Please enter your favorite fruit.
set /p fruit=Example: apple

endlocal
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>sample.cmd
C:\Users\user>setlocal
C:\Users\user>echo Please enter your favorite fruit.
Please enter your favorite fruit.
C:\Users\user>set /p fruit=Example: apple
Example: apple
Use @echo off by default

To hide unnecessary command lines for the whole batch file, put @echo off at the top. Use @rem when you only want to suppress a single line.

Writing a Comment at the End of a Line

rem is treated as a command, so to place it after another command on the same line, join them with &.

echo Starting process & rem start message
A rem line is a comment all the way to the end

Everything after rem, including &, is treated as part of the comment. Commands placed after rem on the same line are not executed.

Is It OK to Use ::?

You will often see :: comment in batch files.

However, :: is not an official comment command. It abuses label syntax, so it can behave unexpectedly inside parenthesized blocks or when combined with redirection.

Use rem when reliability matters

For maintainability and safety, rem is the safer choice for comments. It is especially recommended for reusable or shared batch files.

Commenting Out Code

Batch files have no official multi-line comment syntax like /* ... */ in C.

To temporarily disable several lines, adding rem to each line is the clearest and safest approach.

rem copy source.txt backup\source.txt
rem move source.txt archived\source.txt
rem echo Done

Character Encoding Pitfalls

rem itself does not cause errors. The usual problem is a mismatch between the batch file’s character encoding and the code page used by cmd.exe.

Batch files that contain Japanese or other non-ASCII comments can show garbled text depending on the environment.

UTF-8 is not always safe

Batch files with non-ASCII text can behave differently depending on the environment, whether saved as UTF-8 or Shift_JIS. Save in the encoding your existing setup uses, and test on the real machine, including chcp 65001 if needed.

Summary

  • The official way to write a comment is rem comment
  • Comments appear on screen because of command echo, not because rem prints them
  • Use @echo off for the whole file, or @rem for a single line
  • :: is a shortcut; rem is safer when robustness matters
  • With non-ASCII comments, check the combination of file encoding and code page

Practice Questions

Practice Problem

Which of the following is treated as an official comment in a batch file?

回答がサーバーに送信されることはありません
Practice Problem

What do you often write first to suppress command line display for the entire batch file?

回答がサーバーに送信されることはありません
#Command Prompt #Batch File #Comment #rem