Command Prompt Echo: How to Use It
In this article
The command prompt echo command displays text or controls whether commands appear on the screen when running a batch file. It's a simple but powerful tool for scripting and troubleshooting in Windows. You can use echo to show messages, pause scripts, or toggle command visibility. No downloads or special permissions are needed—echo is built into Windows Command Prompt.
What You'll Need
- A Windows PC with access to Command Prompt
- Basic familiarity with typing commands
- (Optional) A text editor like Notepad for creating batch files
Step-by-Step
- Open the Start menu, type "cmd", and press Enter to open Command Prompt. Alternatively, press Windows + R, type "cmd", and press Enter.
- Type
echo Hello Worldand press Enter. The text "Hello World" will appear on the next line. - To turn off command echoing in a script, type
echo offat the beginning of a batch file. This prevents each command from being displayed when the script runs. - To suppress the
echo offcommand itself from appearing, start your batch file with@echo off. The @ symbol stops that single line from being shown. - Use
echo.(with a period) to print a blank line. This improves readability in scripts or output. - To display special characters like >, <, |, or %, escape them with a caret (^). For example:
echo File ^> output.txtwill show "File > output.txt". - To append text to a file, use
echo This is a line >> myfile.txt. This adds the line without overwriting existing content. - To overwrite a file with new text, use a single >:
echo New content > myfile.txt. - To turn command echoing back on in a script, type
echo on. This is useful for debugging specific sections. - To check the current echo status, run
echowithout arguments. It will respond with "ECHO is ON" or "ECHO is OFF".
Common Mistakes
- Forgetting the space after
echo.—it must beecho., notecho.with no space. Without the space, it may produce an error. - Using
echo offwithout the @ symbol in a batch file, causing the command itself to appear before hiding others. - Not escaping special characters, leading to syntax errors or unintended redirection.
- Using
>instead of>>when you want to add to a file, accidentally overwriting important data. - Assuming echo supports formatting like colors or fonts—Command Prompt echo does not support rich text.
Tips
- Use
@echo offat the top of every batch file for cleaner output. - Combine echo with pause:
echo Process complete. && pauseto show a message and wait for user input. - Use echo to create quick files:
echo Hello > test.txtcreates a file instantly. - Use multiple echo lines in a batch file to build user-friendly menus or status updates.
- Redirect echo output to a log file for debugging:
echo Error at %time% >> log.txt. - Use variables with echo:
set name=John && echo Hello %name%displays "Hello John".
Troubleshooting
If echo isn't working as expected, try these steps in order:
- Check for typos—ensure there's a space after
echoand correct use of symbols like >, >>, and ^. - If a batch file shows all commands despite
echo off, verify you used@echo offat the very beginning. - If special characters cause errors, escape them with ^: for example, use
^&instead of&. - If output isn’t appearing in a file, confirm the file path is correct and you have write permissions in the directory.
- If echo returns "The system cannot find the file specified" when redirecting, create the file first or run Command Prompt as administrator if in a protected folder.
- Run Command Prompt as administrator only if necessary—most echo operations work in standard mode.
- Restart Command Prompt if it behaves unexpectedly after long use.
Frequently Asked Questions
Can echo display variables?
Yes. Use echo %variablename% to display the value of a defined variable. For example, after set name=Tom, echo Hello %name% shows "Hello Tom".
How do I echo a blank line?
Type echo. with a period and no space between echo and the period. This is the standard way to output an empty line in batch scripts.
Does echo work in PowerShell?
Not directly. PowerShell uses Write-Output instead. However, echo is aliased to Write-Output in PowerShell, so it may appear to work but behaves differently than in Command Prompt.
Can I use echo to create a file?
Yes. Use echo Text > filename.txt to create a new file with that text. If the file exists, it will be overwritten.
Why does echo off still show the first line?
Because echo off only prevents commands after it from displaying. To hide that line too, start with @echo off. The @ suppresses the command itself.
Can echo show output in color?
No. Command Prompt echo does not support colored text. For color, use third-party tools or switch to PowerShell with Write-Host -ForegroundColor.