ECHO: the batch-printing tool

The ECHO command is used for what the print command does in other programming languages: To display something on the screen. It can be used to tell the user what the batch file is currently doing. It is true that batch programs display all commands they are executing but sometimes they are not enough and it is beter to also insert ECHO  commands , which give a better description of what is presently being done. Say, for example, the following batch program, which is full of the ECHO command deletes all files in the c:\ windows \temp directory

ECHO This Batch file deletes all unwanted temporary files form your system.

ECHO Now we go to the Windows\tem directory.

cd temp

ECHO Deleting unwanted temporary filees…..

del *.temp

ECHO your system is Now Clean

 Now let us see what happens when we execute the above snippet of batch code.

        C:\Windows>batch filename

        C:\ Windows>ECHO This Batch file deletes all unwanted temporary files form your system

        C:\ Windows >ECHO Now we go to the windows \temp\directory.

        C:\ Windows>CD temp

        C.:\ windows\>ECHO Deleting unwanted temporary files

Deleting unwanted temporary files….

     C:\ Windows> Del *.tep

     C:\ Windows >ECHO your system in Now clean

Your system is now clean

 

 The above is a big mess! The problem is that DOS is displaying the executed command and also the statement within the ECHO command. To prevent DOS from displaying the command being executed simply precede the batch file with the following command at the beginning of the file.

        ECOH OFF

 Once we add the above line to our temporary files deleting batch program, the output becomes:

 C:\ Windows > Echo Off

This batch file deletes all unwanted temporary files from your system.

Now , We go to the windows\.temp directory.

Invalid directory

Deleting unwanted temporary files….

File not found

Your system is now clean.

But it still show the initial ECHO OFF command. You can prevent a particular command from being shown but still be executed by  preceding the command with a @ sign. So , to hide even the ECHO OFF command, simply replace the first line of the batch file with @ECHO OFF.

You might think that to display a blank line in the output screen, you can simply type EHCO by itself , but that doesn’t work. The ECHO command returns whether the ECHO is ON or OFF. Say, You have stared your batch file with the command ECHO OFF and then in the later line give the command ECHO, then it will display ‘ECHO (ECHO followed by a dot). Simply leaving a blank line in the code too displays a blank line in the output.

You can turn ON the ECHO any time by simply giving the command ECH ON. After turning the echo on , if you give the command ECHO then it will return ‘ECHO is on’.

 

 Next---->