Batch file programming is a very useful way to automate small, repetitive, tasks. For those who are new to creating batch files, the Windows Command Line Programming tutorial is a good starting place to read about the basics of batch file programming.
The ECHO command can be used for 3 purposes:
One important point to remember is that ECHO relates only to the operating system standard output. For example, program output (which includes many of the standard command line utilities) is not affected.
This can be tested by entering the command line (Start->Run... then enter cmd and press enter, in Windows) and typing ECHO OFF(and then pressing enter). Keypresses remain echoed, as does program output (for example, the dir command still produces the desired effect). However system information, like the prompt, disappears. Luckily ECHO can be easily turned back on again.
Using the ECHO keyword with either ON or OFF turns screen ECHO on or off. In a batch file, if ECHO OFF is specified right at the start, then only command output, or messages displayed using the ECHO keyword will be output to the screen.
There is no need to end the batch file with ECHO ON, as the echo status will be restored once the batch script returns to the command prompt. Any time that ECHO is off, a message can be displayed by using the ECHO keyword.
The parameter given to the ECHO keyword represents the text to be echoed to the screen. So, the following will echo some text, and one of the parameters from the command line:
If the ECHO OFF command is not included, then each line from the batch script is displayed before it is executed - which is useful for debugging, but not necessarily for deployment. Without any parameters, the ECHO keyword will indicate the current status.
The final variation is the simplest : simply typing ECHO by itself, or using ECHO without parameters in a batch file, will display the current status, which will be one of:
or
It is interesting to note that this works even when ECHO is off! In addition, readers might be wondering how it is possible to display a blank line, given that ECHO by itself returns the ECHO status. The answer is simple:
The period (.) after the ECHO keyword is not echoed, but a new line is inserted. To echo the period, just introduce a space between the period and the ECHO keyword.