fortypoundhead.com

ECHO

Primary Category = Windows Commandline

Posted On 2009-01-16 by FortyPoundHead
Keywords: Command Reference
Tags: Windows Commandline Active Directory Active Directory Windows Linux Linux
Views: 1494
Rating: / 5.00

  • 1
  • 2
  • 3
  • 4
  • 5

 

Display messages on screen, turn command-echoing on or off.
syntax
ECHO [ON | OFF]

ECHO [message]

Key


ON : Display each line of the batch on screen (default)

OFF : Only display the command output on screen

message : a string of characters to display


Type ECHO without parameters to display the current echo setting (ON or OFF). In most batch files you will want ECHO OFF, turning it ON can be useful when debugging a problematic batch script.

In a batch file, the @ symbol is the same as ECHO OFF applied to the current line only.

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

Command characters will normally take precedence over the ECHO statement, e.g. The redirection and pipe characters: & < > | ON OFF .

To override this behaviour you can escape each command character with ^ as follows:
ECHO Nice ^&Easy

ECHO Salary is ^> Commision

ECHO Name ^| Username ^| Expiry Date

ECHO:Off On Holiday


Echo a Variable

To display a department variable:

ECHO %v_department%

If the variable does not exist - ECHO will simply return the text "%v_department%"

This can be extended to search and replace parts of a variable or display substrings of a variable. You can also redirect the echoed output from the screen into a file.

Echo a file

see the TYPE command for this

Echo a sound

The following command in a batch file will trigger the default beep on most PC's

ECHO <^G>

Use Ctrl-G (or 'Alt' key, and 7 on the numeric keypad) to get this character (ascii 7)

Alternatively where a sound card is available:

START/min sndrec32 /play /close %windir%mediading.wav

or

START/min mplay32 /play /close %windir%mediading.wav

Echo a blank line

The following command in a batch file will produce an empty line

ECHO.

Echo text into a stream

Streams allow one file to contain several separate forks of information (like the macintosh resource fork)

The general syntax is

Echo Text_String > FileName:StreamName

Only the following commands support the File:Stream syntax - ECHO, MORE, FOR

Creating streams:

Echo This is stream1 > myfile.dat:stream1

Echo This is stream2 > myfile.dat:stream2


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


A data stream file can be successfully copied and renamed despite the fact that most applications and commands will report a zero length file. The file size can be calculated from remaining free space. The file must always reside on an NTFS volume.

About the Author

FortyPoundHead has posted a total of 1975 articles.

You can find more information from FortyPoundHead by visiting .

Comments On This Post

No comments on this post yet!

 

Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.161.208.7

Before you can post, you need to prove you are human. If you log in, this test goes away.