echo - Display Text

Maintained on

What is the echo command?

The echo command displays text in Command Prompt and batch files. It also turns the display of the commands themselves (the “echo”) on or off.

  • Display text: echo Hello
  • Control command display: echo off / echo on
  • Combined with redirection, it can also create empty files or write text to files

This page explains the basics of echo, the meaning of @echo off, and how to handle special characters, with sample code.

echo command syntax

echo [<message>]
echo [on | off]
SyntaxBehavior
echo <text>Displays the specified text
echo onTurns command display on (default)
echo offTurns command display off
echoShows the current echo state (such as ECHO is on.)
@<command>A leading @ hides the command itself on that line

Basic usage

In Command Prompt

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>echo Hello, World!

When you run this command, the text “Hello, World!” that follows echo is displayed.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>echo Hello, World!
Hello, World!
C:\users\user>
おすすめ書籍※ 広告を含む場合があります
中小企業経営者のためのRPA入門 RPA導入を成功させる方法

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

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

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

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

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

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

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

In a batch file

@echo off
setlocal

echo Hello, World!

endlocal
exit

When you run this batch file, Hello, World! is displayed just as in Command Prompt.

What “@echo off” means

echo on and echo off switch whether the command itself is shown on screen when it runs.

  • echo on (default): both the command and its result are displayed
  • echo off: only the result is displayed

If you run a batch file as is, every command is printed line by line, which makes the output hard to read. That is why batch files usually start with @echo off.

The leading @ means “do not display the command on this line.” Without it, the echo off line itself would still be printed, so the @ is added only to the first line.

@echo off
echo Only the result of this line is displayed
Hiding only specific lines

Instead of writing @echo off, you can put @ at the start of just the lines you want to hide. Example: @del temp.txt

Displaying a blank line

Use echo. (a period right after echo) to display a blank line.

A bare echo does not print a blank line

Running echo alone shows the echo state, such as ECHO is on. (or ECHO is off. after echo off), instead of a blank line. In a batch file, echo %UNDEFINED_VAR% with an undefined variable expands to nothing and gives the same result. When you only want a blank line, echo. is the safe choice.

In Command Prompt

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>echo.

In a batch file

@echo off
setlocal

echo Hello, World!
echo.
echo This is a new line.

endlocal
exit

Advanced usage

Displaying environment variables

To display an environment variable or a variable’s value, use the %variable name% format.

In Command Prompt

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>echo %USERNAME%
user01
C:\users\user>

This displays the name of the signed-in user.

In a batch file

@echo off
setlocal

echo Your username is %USERNAME%.

endlocal
exit

When you run this batch file, your username is displayed.

Displaying calculation results

You can calculate with set /a and display the result with echo.

In Command Prompt

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>set /a result=3+4
7
C:\users\user>

In Command Prompt, set /a prints the result, 7, directly.

In a batch file

@echo off
setlocal

set /a result=3+4
echo The result is %result%.

endlocal
exit

When you run this batch file, The result is 7. is displayed.

Displaying special characters

The characters &, |, <, > and ^ have special meanings in Command Prompt, so passing them to echo as is does not display them. To display them, put ^ in front of the character. In a batch file, write % as %%.

@echo off
echo A ^& B
echo 50%%
echo 1 ^> 0

This displays A & B, 50% and 1 > 0.

Using ">" writes to a file

echo Hello > memo.txt sends the output to a file instead of the screen. You can use this to create text files with echo. See the related articles for details.

Summary

  • echo <text> displays text
  • Start batch files with @echo off to hide the commands themselves
  • Use echo. for a blank line (a bare echo shows the echo state)
  • Escape special characters such as & and > with ^

Quiz

Practice Problem

Which command is the safe way to display a blank line?

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

Which line, placed at the top of a batch file, also hides the echo off line itself?

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