DEV Community

Victor James
Victor James

Posted on • Originally published at windowscmd.com on

ECHO

ECHO

ECHO

This windows command-line tool is to display the message on the screen. This command turns the ON/OFF command echoing feature.

CMD Line

CMD Line is a text-based interface that transfers the command from the user to the OS.

CLI-Command Line Interpreter

The command-line interpreter (CLI) for windows is CMD.EXE. Also, you can use PowerShell which can automize many system administration tasks and these tasks are not approachable in command prompt. With the help of the CLI, you can communicate with your system by typing the text in commands. As a result, your system answers to the text that you have typed previously, and then the user can proceed with the next command line that shows up.

To open the Run command Window

Run command window helps you to run programs, open the files and folders. And there are several ways to open up the run command dialog box. This run command box is useful for you to head straight to the destined program easily.

By using the Keyboard shortcut Key:

WINDOWS+R

The shortcut key method to the run command box is the most commonly used one. Also, this method is in all versions of Windows. You need to press the Windows+ R key concurrently to open the Run command dialog box.

Run command box
Run command box

What does the ECHO command do?

This command-line tool is to display the message on screen , and you can turn the command echoing on and off. If you want to display the current echo setting , type the command without parameters. This command is an internal command.

Syntax


      ECHO [ON | OFF] 
      ECHO [message]
      ECHO /?

Enter fullscreen mode Exit fullscreen mode

Parameter Explanation

  • ONDisplay each line of the batch on screen.
  • OFF – This displays only the command output on screen.
  • message – a string of characters to display.
  • ? – Display help

  • Turning ON can be useful when debugging a problematic batch script , but in the batch files, you have to turn ECHO OFF.

  • The @ symbol at the beginning of a line is similar to ECHO OFF applied to the current line, only in a batch file.

Usually, a command takes effect from the next line onwards, @ is a rare example of a command that takes effect immediately.

Echo text into a FILE

General syntax


Echo This is some Text > FileName.txt

Enter fullscreen mode Exit fullscreen mode

In order to avoid the space , you can use


Echo Some more text>FileName.txt

Enter fullscreen mode Exit fullscreen mode

For to create an empty file use


Echo. 2>EmptyFile.txt

Enter fullscreen mode Exit fullscreen mode

Escape Command characters

  • The command characters usually take priority over the ECHO statement.

    • For example, The redirection and pipe characters: & < > | ON OFF
  • You can escape each command character with ^ or : to override this behavior


ECHO Nice ^&Easy
ECHO Salary is ^> Commision
ECHO Name ^| Username ^| Expiry Date
ECHO:Off On Holiday
ECHO: /? Will display help

Enter fullscreen mode Exit fullscreen mode
  • Another method is by using SET /P which will display the string without interpreting anything

C:\> <nul set/p "_any_variable=string to emit"
e.g.
C:\> <nul (set/p "_demo=This & That ^more < or > less")
This & That ^more < or > less

Enter fullscreen mode Exit fullscreen mode

Echo a Variable

For to display a department variable


ECHO %_department%

Enter fullscreen mode Exit fullscreen mode

A more robust alternative is to separate with : instead of a space


ECHO:%_department%

Enter fullscreen mode Exit fullscreen mode

Using a colon like this will sanitise the values ON /OFF /? So for example,


Set _var=OFF
Echo %_var%

Enter fullscreen mode Exit fullscreen mode

Turns OFF the Echo


Echo:%_var%

Enter fullscreen mode Exit fullscreen mode

This will simply display “OFF”

Limitations:

ECHO: will return the variable name”%_var%”, If the variable does not exist.

If in case you are using Delayed Expansion (!_var!) AND the syntax to search and replace parts of a variable or display substrings of a variable, then the Echo: syntax will not work. You can work around this by using an intermediate variable or just returning to the default parse time expansion of variables.

Echo a sound


ECHO ^G

Enter fullscreen mode Exit fullscreen mode

The command in a batch file will trigger the default beep on most PCs.

  • Use Ctrl-G or ‘Alt’ key, and 7 on the numeric keypad, to type the BELL character
    • The default beep is now played through the speakers/audio system, however, if you select the ‘No Sounds’ scheme in
    • Control Panel > Sounds > Change system sounds, then the default beep will not play.

Alternatively using Windows Media Player


START/min "C:\Program Files\Windows Media Player\wmplayer.exe" %windir%\media\chimes.wav

Enter fullscreen mode Exit fullscreen mode

Echo a blank line

To produce an empty line using


Echo:
or
Echo.

Enter fullscreen mode Exit fullscreen mode

Using ECHO. is troublesome because it will search for a file named “echo” if the file is found that raises an error. If the file does not exist, then the command does work, but this still makes Echo. Somewhat slower than echo:

To ECHO text without including a CR/LF


<nul (set/p _any_variable=string to emit)

Enter fullscreen mode Exit fullscreen mode

Echo the system PATH

By replacing the semicolons with new lines , you can view each item in the path on a single line


ECHO:%PATH:;= & ECHO:%

Enter fullscreen mode Exit fullscreen mode

Echo text into a stream

The stream supports one file to contain several forks of information.

For that use general syntax


Echo Text_String > FileName:StreamName

Enter fullscreen mode Exit fullscreen mode

The comments mentioned below will only support the file: Stream syntax – ECHO, MORE, FOR


Echo This is stream1 > myfile.dat:stream1 
Echo This is stream2 > myfile.dat:stream2

Enter fullscreen mode Exit fullscreen mode

Displaying streams:


More < myfile.dat:stream1 
More < myfile.dat:stream2

FOR /f "delims=*" %%G in (myfile.dat:stream1) DO echo %%G
FOR /f "delims=*" %%G in (myfile.dat:stream2) DO echo %%G

Enter fullscreen mode Exit fullscreen mode

In spite of the fact that most applications and commands will report a zero-length file, a data stream file can be successfully copied and renamed. The file size is calculated by the free space and the file must be in the NTFS volume.

This command does not set or clear the Errorlevel.

Verdict

In this guide, we have seen the ECHO command, which is used to display the message on the screen. If you have any suggestions, let us know in the comment section. Thank you for reading this article.

Related articles

  • ERASE The Erase command deletes one or more files or file systems. Also, this command is similar to the Del windows command. ERASE is an internal command. ERASE command is equivalent to DEL.
  • ECHO The ECHO windows command-line tool is to display the message on the screen. This command turns the ON/OFF command echoing feature. ECHO is an Internal command.
  • ENDLOCAL The End local command is to end localization of environment changes in a batch file which was modified by the set local command. ENDLOCAL is an internal command.
  • IF The IF windows command-line tool performs conditionally processing in batch programs. This command is for Conditionally performing a command.
  • LGPO The LGPO windows command-line tool is for the Local Group Policy Object utility. This command automates the management of local group policy.

The post ECHO appeared first on Windows Commands- SS64 Commands.

Discussion (0)