When a batch file is being executed, if echo is turned on, it would print the command currently it’s running on to the command prompt. By default echo is turned on for any batch file.
We can turn off echo by including the following line in the beginning of the file.
Command to turn on echo:
We can turn on or turn off echo at any point in a batch file. For example, you may want echo to be on for certain commands in the batch file, and then you may turn it off, and then again you can turn it on.. likewise.
I have the below batch file named echoExample.bat :
date /t @echo off echo echo turned off date /t @echo on echo echo turned on date /t @echo off echo echo turned off date /t
Now when I run the batch file, I see the below output.
c:\>echoExample.bat c:\>date /t Mon 02/13/2012 echo turned off Mon 02/13/2012 c:\>echo echo turned on echo turned on c:\>date /t Mon 02/13/2012 echo turned off Mon 02/13/2012 c:\>
In the batch file, we have executed ‘date’ command 4 times. But the command is echoed only twice in the output. You can notice that for the 2nd and 4th times when echo is turned off, it does not echo the command in the output.