ECHO - CMD
Overview
The ECHO command in Windows CMD is used to display messages or turn on/off the command echoing feature in the command prompt. Its primary purpose is to show text on the screen or to control the visibility of commands in batch scripts. This command is most effective in scripting and automation to provide feedback, debug information, or to show the status of script execution.
Syntax
The basic syntax for the ECHO command is:
ECHO [ON|OFF|message]
ECHOwithout parameters displays the current echo setting (ECHO is onorECHO is off).ECHO [message]displays the message on the screen.ECHO.can be used to display a blank line.
Options/Flags
ON: Turns on the command echoing, causing each command in a batch file to be displayed before it is executed.OFF: Turns off the command echoing, which prevents commands within a batch file from being displayed as they are executed.[message]: Specifies the text message to be displayed. Any valid string can be used as a message.
Examples
-
Display a Message:
ECHO Hello, world!This command will output:
Hello, world! -
Turn Off Command Echoing:
ECHO OFFThis is commonly used at the beginning of batch files to make the output cleaner.
-
Display a Blank Line:
ECHO.Useful for adding space in output for better readability in scripts.
-
Combining Messages and Commands:
ECHO The current date is: DATE /TThis sequence displays a custom message followed by the current date.
Common Issues
-
Extra Spaces in Output:
Sometimes extra spaces are added before the message if not formatted properly. UsingECHO.[message](note no space between.and[message]) can help avoid unintentional leading spaces. -
Echoing Special Characters:
Special characters might need to be escaped or quoted to behave as expected, for instance,ECHO ^|to display a pipe character (|).
Integration
ECHO can be integrated with other CMD commands for more complex scripts. For example:
ECHO Listing all files in the directory:
DIR /B
PAUSE
This script segment displays a message, lists all files in the directory in a simple format, then waits for the user to press a key.
Related Commands
SET: Often used withECHOto display variable values (ECHO %VARIABLE%).IF: Used for conditional execution in scripts.PAUSE: Can be paired withECHOfor messages before pausing execution.
For further reading and more detailed information, refer to the official Microsoft documentation: Command-Line Reference