At the beginning of a batch script, I saw the command:
@echo %off
To my surprise it has the same effect of:
@echo off
What is the effect of the '%' prefix?
I've never seen it before. It doesn't work in the cmd console -- only in a .bat script. But I have a guess.
In a cmd console window if you @echo off
, that results in command prompts being hidden, just like it does in a .bat script. To reveal the prompts again, you have to echo on
. The difference is that in a .bat script, percent signs need to be doubled to represent a literal %
string character, whereas in the cmd console they do not. The result is that @echo %off
in a cmd console results in the string %off
being echoed to stdout.
With this in mind, I'm guessing the author intended this hack to avoid problems encountered by users who copypaste the script into a cmd console window, rather than as intended into a .bat script. With %
added, the command is neutered in the console, but still achieves its intended effect when run from a .bat script. Without the %
, the console would appear to hang after all instructions have completed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With