Batch file : ECHO command

by admin on February 13, 2012

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.

@echo off

Command to turn on echo:

@echo on

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.

Example:

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.

{ 0 comments… add one now }

Leave a Comment

HTML tags are not allowed.

Previous post:

Next post: