问题
When writing batch files,
I found out some people uses Echo.
,Echo/
,Echo(
etc...These echo a blank line, so what is the difference between these Echo[Special Character]
?
回答1:
You can use many different characters with echo
.
One of .[]+\:/,;=(
.
But there are multiple requirements for a good choice.
It should create an empty line (not
ECHO iS OFF
)- It should be able to output any content if used with a (delayed) variable
- It shouldn't fail when a special namend file exists in the current directory
The first point works for all characters (from the list).
The second point fails for \:.
with content like \..\..\..\windows\system32\calc.exe
@echo off
setlocal EnableDelayedExpansion
set var=\..\..\..\windows\system32\calc.exe
echo.!var!
,;=
fails with /?
and /
fails with ?
@echo off
setlocal EnableDelayedExpansion
set var=/?
echo=!var!
The third point fails for .[]+
echo echo HELLO FROM %~f0 > echo[.bat
echo[ This fails
The only one that works always is echo(
来源:https://stackoverflow.com/questions/41647005/difference-between-echospecial-character