Our social:

How to Use Echo Command In Batch ?

Echo Command In Batch :



The ECHO command is used for what the print command does in other programming languages.
 don't understand ? It Is used to Display something on a screen .It Can Be Used To Tell the user what the batch file is currently doing.It Is True that batch programs display all command they are executing but sometimes they are not enough and it is better to also insert echo command . Which Shows You Text or whatever that you want to print . 

Also read : Top 10 programming languages 


Examples Of Echo Command :      

   

suppose If You Want To Print "I LOVE BATCH PROGRAMMING"  Then Will We use Echo Command .

@echo off
Echo I Love Batch Programming
pause

It Will Display I Love Batch Programming .

Let's Look One Another Example .

ALSO READ : HOW TO BECOME ETHICAL HACKER ?

How To Delete Temp directory Using Batch File Programming ?


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 from your computer.
ECHO Now We Are Ready . We go to the windows\temp directory.
cd temp
ECHO Deleting unwanted temporary files......
del *.tmp
ECHO Your System Is clean 


How To Use Echo Off ?


What is problem In Above program ? The above program is big mess !!! The Problem Is That DOS Is Displaying the executed command and also the statement within 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 .

ECHO 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 computer.
Now We Are Ready . We go to the windows\temp directory.
Invalid directory    
Deleting unwanted temporary files......
File Not Found 
Your System Is clean 
                                               

How To Use @ECHO OFF command ?


In Above Program It Still Shows 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 ECHO OFF command , simply replace the first line of batch file with @ECHO OFF.


How To Display A Blank Line In Batch File Programming ?


Also read  : PERL PROGRAMMING LANGUAGE 

You Might think that to display a blank line in the output screen , you can simply type ECHO by itself , but that does not work . The ECHO Command returns whether the ECHO  is ON or OFF .
Say You have started your batch file with the command ECHO OFF and then in later line give the command ECHO ,Then it will display 'ECHO is off" on the screen . You Can display A blank line by giving the command ECHO ( ECHO followed by a dot ) . Simply leaving a blank line in the code too display a blank line in the output .

You Can Turn ON the ECHO any time by simply giving the command ECHO ON . After turning the echo on , if you give the command ECHO then it will return 'ECHO is on '.



Any Queries ?  Leave Comment ..