Echo in the CMD: Discover the secrets of this essential Windows command

Are you using Windows and want to learn how to use the command line ? Have you heard of the echo command, but don't know what it is for or how to use it? Don't panic, in this article you will find out what the echo command is, how to use it to display messages or modify the echo parameter , and what special characters you need to know to escape reserved symbols.

Quick video tutorial on the “echo” command , a few things to understand:

What is the echo command?

The echo command is an instruction that you can write in a black window called Command Prompt. This window allows you to communicate with your computer by giving it written orders. The echo command is used to display words or sentences in this window. For example, if you write: echo Hello You will see the word Hello appear on the window.

picture 196

The command echo is an option which means that the orders you write are also displayed on the window before being executed. For example, if you write: dir You will see the word dir appear followed by the list of files and folders located in the current directory.

picture 197

Command echo is enabled by default , but you can disable it if you want to hide the commands that you write to a special file that is called a batch file . A batch file is a file that contains several orders in a row and can be executed automatically .

The syntax of the echo command is as follows:

echo [ ]

echo [on | off]

The first <message> parameter specifies the text to display on the screen. The second parameter [on | off] enables or disables the command echo feature. If you use the echo command without parameters, it displays the current echo setting (on or off).

This article might interest you: Ctrl + Z: What is this amazing keyboard shortcut for?

How to use the echo command to display messages?

Echo cmd

The echo command is particularly useful when echo is disabled . To display a multi-line message without displaying commands, you can include multiple echo commands after the echo command is disabled in your batch program. For example, if you want to display the following message:

Good morning,

This is an example

multiline message.

Bye.

You can use the following batch file:

@echo off

echo Hello,

echo This is an example

multiline message echo.

echo Goodbye.

picture 198

The @ symbol in front of the first command prevents that particular command from being echoed . If you want to display a blank line on the screen , you can use the echo command. without space before the period. Otherwise, the dot will appear in place of a blank line.

picture 199

How to use echo command to change echo setting?

If you want to enable or disable command echo echo on or echo off command . For example, if you want to disable command echo at the command prompt, type:

echo off

picture 200

After Echo is disabled, Command Prompt does not appear in the Command Prompt window. To display the Command Prompt again, type:

echo on

picture 201

If you want to prevent all commands from echoing in a batch file , include the echo off command at the beginning of the file. For example, if you want to run the following commands without displaying them on screen:

dir

break

cls

You can use the following batch file:

@echo off

dir

break

cls

What special characters do you need to know to use the echo command?

Some characters have special meaning for the Windows shell and cannot be used directly in the echo command. These are the following characters:

  • <
  • >
  • |
  • &
  • ^

These characters are used to redirect the output of a command , create a pipeline between two commands , execute two commands at the same time, or escape a special character . To display these characters with the echo command , you must use an escape character in front of them. The escape character is the symbol ^. For example, to display the following message:

  • A>B | C&D^E

You must type the following command:

  • echo A-^>B ^| C^&D ^^ E
picture 202

Note that you must type two ^ symbols to display a single ^ symbol. Likewise, if you want to display an exclamation point (!), you must use double quotes and a ^ symbol in front of the exclamation point. For example, to display the following message:

  • Bonjour Monde!

You must type the following command:

  • echo “Hello World^!”

You can also use two ^ symbols without needing double quotes. For example :

  • echo Hello World^^!
picture 203

echo command FAQ

Here are some frequently asked questions about the echo command and their answers.

How to use the echo command to redirect output to a file?

If you want to save the result of the echo command to a file, you can use the > symbol to redirect the output to a file. For example, if you want to create an XML file with the echo command, you can type:

  • echo ^ > myfile.xml

The > symbol creates a new file or overwrites the contents of an existing file. If you want to add content to an existing file, you can use the >> symbol instead. For example, if you want to add a line to the previous XML file, you can type:

  • echo >> myfile.xml

How to use the echo command to display environment variables?

If you want to display the values ​​of environment variables with the echo command , you must use the % symbol around the variable name. For example, if you want to display the current user's name , you can type:

  • echo %USERNAME%

If you want to display all environment variable names and values, you can type:

  • set

How to use echo command to display time and date?

If you want to display the time and date with the echo command, you can use the %TIME% and %DATE% environment variables. For example, if you want to display the current time and date, you can type:

  • echo It is %TIME% on %DATE%
picture 205

You can also use the time and date commands to view or change the system time and date .

How to use the echo command to display a message without newlines? 

If you want to display a message with the echo command without going to the next line, you can use the /n option. For example, if you want to display two messages on the same line, you can type: echo /n Hello echo /n world

picture 204

How to use the echo command to display special characters?

If you want to display special characters with the echo command, such as quotes, angle brackets, or the redirection symbol, you must precede them with the ^ symbol to escape them. For example, if you want to display the text “ Hello > World”, you can type: echo ^“Hello ^> World^”

Conclusion

The echo command is a useful command for displaying messages on the screen or command echo setting It also allows you to create simple text files or manipulate environment variables . To use the echo command correctly , you need to know the special characters to escape with the ^ symbol . We hope this article has given you a better understanding of the echo cmd command and its applications.

Previous article How to open a GPX File? Learn how to use them!
Next article The Broadcom BCM20702A0 driver: Understanding its role in Windows 10
Hello me, it's François :) Editor in my spare time who loves sharing his passion: TT High tech! 😍 Whether it's hardware, software, video games, social media and many other areas on the site. I share with you my analyses, my tests, tutorials and my favorites on various media. I am a knowledgeable and demanding technophile, who does not just follow fashion, but who seeks to guide you towards the best solutions. So stay tuned!