启用延迟扩展重定向特殊字符

此示例将特殊字符 ! 回显到文件中。这仅在禁用 DelayedExpansion 时有效。启用延迟扩展后,你需要使用三个插入符号和一个感叹号,如下所示:

@echo off
setlocal enabledelayedexpansion

echo ^^^!>file
echo ^>>>file

goto :eof    

    ^> is the text
    >> is the redirect operator

pause
endlocal
exit /b

此代码将以下文本回显到文件中

!
>

^^^ escapes the ! and echos it into the file
^> escapes the > and echos it into the file