I've been aware of the technique of using a special character immediately after the ECHO command instead of a space for a very long time. As hardcore scripters will be aware of already, this is done mainly to safely use the ECHO command where the argument to the ECHO command has the possibility of resolving as empty. If the special character technique is not used, the ECHO command would output ECHO ON, in such cases. Additionally, using such a special character has the advantages of changing the parsing behavior to allow using certain special characters in the argument itself, safely, as well as having the added benefit, seemingly, of being more performant when certain special characters are used.
Quite some time ago, I encountered a treatment/post on Stack Exchange or elsewhere on some forum or Q&A site, that extensively analyzed and compared the safety and performance benefits of different special characters. That post indicated that the character I had been using thus far (
, while being among the best, was not THE best option, IIRC. A different character topped the list, and there were some pros/cons associated with certain special characters.
I've been trying to trace that post recently, but so far have come empty.
I think the information that was available on that post was very valuable and those using SO would find this so as well.
Does anyone have access to the above mentioned information, or is anyone interested in attempting to duplicate the said treatment/analysis?
Command I currently use: ECHO(Hello, World!
Web Search keywords tried: windows batch file script echo safe escape character fast
, and variations thereof.
Expected: A thorough, and preferably an exhaustive treatment of all ASCII special characters. As the list of ASCII characters is limited and well defined, I don't believe this question is subjective as posed. However, if anyone still thinks it's subjective or too broad, they may instead limit answers to picking a single best character found experimentally under the criteria of safety and performance, in a scientific and repeatable manner.
Note: This is not simply a question about using special characters in batch files/CMD, as most of the other answers coming up seem to be about.
In my opinion the echo(
is the best and only choice, because it works in nearly every situation [See #The only problem]. All other variants have some drawbacks.
Some time ago, I tested all possible echo<character>
variants at dostips: ECHO. FAILS to give text or blank line
I tested different use cases:
All, but echo<space>
can output an empty line
Problematic texts are /?
, ON
, OFF
or ..\..\..\..\windows\system32\calc.exe
These fail with a simple /?
or just ?
set "var=/?"
echo;%var%
echo,%var%
echo=%var%
echo %var%
set "var=?"
echo/%var%
These fail with ..\..\..\..\windows\system32\calc.exe
set "var=..\..\..\..\windows\system32\calc.exe"
echo\%var%
echo:%var%
echo.%var%
These variants fails when there exists a corresponding file.
echo[
echo]
echo+
echo.
echo(
... is the usage as command by delayed or FOR-parameter expansion
@echo off
setlocal EnableDelayedExpansion
set "cmd=echo:"
%cmd% Test1 okay
!cmd! Test2 okay
for /F %%C in ("%cmd%") DO %%C Test3 okay
set "cmd=echo("
%cmd% Test4 okay
!cmd! Test5 fail
for /F %%C in ("%cmd%") DO %%C Test6 fail
Test1 okay
Test2 okay
Test3 okay
Test4 okay
Der Befehl "echo(" ist entweder falsch geschrieben oder konnte nicht gefunden werden.
Der Befehl "echo(" ist entweder falsch geschrieben oder konnte nicht gefunden werden.