The command: "ECHO" is on Windows 12, 11, 10, .. , MS Server 2025, 2022, 2019, .. available
The
`ECHO` command in Windows Command Prompt is used to output text to the screen. Here are some examples:
Example 1: Simple text expression:
ECHO Hello, world!
Description: Returns the text
"Hello, world!" on the screen.
Example 2: Save text to a file:
ECHO This is an example > example.txt
Description: Creates a file named
"Example.txt" and stores the text
"This is an example" in it.
Example 3: ECHO without line break:
ECHO| SET /P=This text is output without line breaks
Description: Outputs the text without adding a line break.
Example 4: Variables and ECHO:
SET Name=John
ECHO My name is %Name%
Description: Uses a variable and prints the text
"My name is John".
Example 5: ECHO in a batch file:
@ECHO OFF
ECHO This is a batch file.
ECHO Press a button to continue...
PAUSE > ZERO
Description: A simple batch file that outputs text and waits for user input.
Example 6: ECHO in a loop:
FOR /L %i IN (1, 1, 5) DO ECHO This is line %i
Description: Uses a loop to output the text
"This is line [number]" five times.
Example 7: Show help:
ECHO.
ECHO Example: Using the ECHO command
ECHO.
Description: Uses ECHO to output a blank line and a heading.
The
`ECHO` commands are useful for displaying information while running batch files or while working in the command prompt. Note that some special characters, such as
`>` or
`|`, have special meanings when used in conjunction with
`ECHO` and may need to be treated differently. In this case, you could use quotation marks or escape the special characters with a double arrow (
`^>`,
`^|`).
There are a few important aspects to keep in mind when using the
`ECHO` command in the Windows Command Prompt:
1.
Special character output: Some special characters, such as
`>` or
`|`, may produce undesirable results when used directly with
`ECHO`. In such cases, it is advisable to use quotation marks or escape the special characters.
ECHO "This is an example with > and |"
ECHO This is an example with ^> and ^|
2.
ECHO in batch files: In batch files, it is common practice to use
`@ECHO OFF` at the beginning to suppress the output of each command in the batch file. Then if you want to print out specific commands, you can use
`@ECHO ON` or
`ECHO` in the batch file.
3.
Variables and ECHO: When using variables in conjunction with
`ECHO`, you must ensure that you reference the variables correctly. Variable names are enclosed with
`%`.
SET Name=John
ECHO My name is %Name%
4.
ECHO redirection: You can redirect the output of
`ECHO` to a file. For example:
ECHO This is an example > example.txt
5.
ECHO and Pipe (`|`): If you use
`ECHO` with a pipe (
`|`), make sure it is a single command. In a batch context it might be necessary to use
`CALL ECHO` when combining ECHO with a pipe.
CALL ECHO This is an example | MORE
6.
ECHO without newline: If you want to use
`ECHO` without newline, you can use
`SET /P`.
ECHO| SET /P=This text is output without line breaks
7.
Empty line with ECHO: If you want to output an empty line, you can just use
`ECHO.`.
ECHO.
8.
Use escape characters: When working with special characters directly in the command prompt, it may be necessary to use escape characters (
`^`) to prevent unwanted effects.
ECHO This is an example with ^> and ^|
9.
Show Help: You can use
`ECHO` to show help text or instructions while running batch files.
ECHO.
ECHO Example: Using the ECHO command
ECHO.
It is important to consider the specific requirements of your task and ensure that
`ECHO` is used correctly to achieve the desired results.