Echo off windows script
Displays messages or turns on or off the command echoing feature. If used without parameters, echo displays the current echo setting.
Syntax
Parameters
Parameter | Description |
---|---|
[on | off] | Turns on or off the command echoing feature. Command echoing is on by default. |
Specifies the text to display on the screen. | |
/? | Displays help at the command prompt. |
Remarks
The echo command is particularly useful when echo is turned off. To display a message that is several lines long without displaying any commands, you can include several echo commands after the echo off command in your batch program.
After echo is turned off, the command prompt doesn’t appear in the Command Prompt window. To display the command prompt, type echo on.
If used in a batch file, echo on and echo off don’t affect the setting at the command prompt.
To prevent echoing a particular command in a batch file, insert an @ sign in front of the command. To prevent echoing all commands in a batch file, include the echo off command at the beginning of the file.
To display a pipe ( | ) or redirection character ( or > ) when you are using echo, use a caret ( ^ ) immediately before the pipe or redirection character. For example, ^| , ^> , or ^ ). To display a caret, type two carets in succession ( ^^ ).
Examples
To display the current echo setting, type:
To echo a blank line on the screen, type:
Don’t include a space before the period. Otherwise, the period appears instead of a blank line.
To prevent echoing commands at the command prompt, type:
When echo is turned off, the command prompt doesn’t appear in the Command Prompt window. To display the command prompt again, type echo on.
To prevent all commands in a batch file (including the echo off command) from displaying on the screen, on the first line of the batch file type:
You can use the echo command as part of an if statement. For example, to search the current directory for any file with the .rpt file name extension, and to echo a message if such a file is found, type:
The following batch file searches the current directory for files with the .txt file name extension, and displays a message indicating the results of the search:
If no .txt files are found when the batch file is run, the following message displays:
If .txt files are found when the batch file is run the following output displays (for this example, assume the files File1.txt, File2.txt, and File3.txt exist):
How does echo off and on are executes in same batch script?
How does echo off and on working in the following script and what if we want to use echo off at some places of batch script let’s say outside loops and echo on inside loops how should we do that
If I try to use @ instead of globally make it off by @echo off .Do I have to place ‘@’ in every line?
Here the following code:
Here what the output looks
Please help in understanding the execution
1 Answer 1
The basic points first: you need to differentiate between echo a command when it is executed in a Batch file vs. the output of a command. The output of a command is what the command generates and it is always displayed on the screen (unless there is an output redirection, but that is another story).
The «echo of a command» is a trace of the command that will be executed. If «echo is on», the command itself will be displayed before it is executed.
If «echo is on» you may cancel the echo of a command if you precede it by @ .
You should note that the echo of commands happen when the commands are parsed, that is, reviewed before executed, and that several commands enclosed in parentheses are parsed as a whole. This means that changing the «echo» status inside a code block have not effect for the commands in the block: the echo will have the same status as when the block begins. Of course, if the echo status is changed in the block, it will work for the commands after the block.