≡ Menu

Batch file : ECHO command

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.

10 comments… add one
  • Yoshi

    How to disable echo in the command prompt. The above works for batch file. But I want to disable it when I run commands in cmd.

    • Matthew

      To disable echo in the command prompt, use “echo.” (ECHO followed by a period).

      Example:

      C:\>echo.The command ECHO does not appear

      There is no space after the period.

    • Jeff Savage

      @Matthew, This is not correct. Here is the correct instructions and some additional tips. Have a great day!

      ‘Echo.’ produces a new line. It does not turn off echo.
      ‘Echo off’ turns off echo. ‘Echo on’ turns it back on.
      Adding @ before any line will disable echo for that command.

      Example:
      ‘@time /T’

  • Wellington Torrejais da Silva

    Thanks!

  • Stephan

    Shouldn’t the “@echo on” command line be visible in the output as well because of the @?

  • Gradigan

    Hello, if I am creating a text file through a batch file utilizing an echo command, is there a way to incorporate a return key. Example, if I input

    echo This is a test > Test.txt

    then it creates the Test text file in the directory. But if I wanted to make something like

    This is a test
    This is a test on a second line

    Is this possible, as it is, notepad will simply create one LONG string of text in the file if I attempt, and in a batch file incorporating the return key seems to signify another command. Thank you in advance for the help on an odd question.

    -A newbie

    • Anon

      Have no idea if this will be helpful now, but to not have a continuous string when writing to a text file via batch. You must do the following… echo “msg”>>”file.txt”
      The “>>” causes every msg to enter into the next new line

    • Tiger

      Use this:
      echo This is a test on a second line >> Test.txt

  • Mar Ann

    How to use list of folder (with subfolders) to transfer to other drive. What command should I use?

    • Arthur Wright

      You can use Xcopy to copy folders and sub-folders.

Leave a Comment