啟用延遲擴充套件重定向特殊字元
此示例將特殊字元 !
回顯到檔案中。這僅在禁用 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