This example echoes the special character !
into a file. This would only work when DelayedExpansion is disabled. When delayed expansion in enabled, you will need to use three carets and an exclamation mark like this:
@echo off
setlocal enabledelayedexpansion
echo ^^^!>file
echo ^>>>file
goto :eof
^> is the text
>> is the redirect operator
pause
endlocal
exit /b
This code will echo the following text into the file
!
>
as
^^^ escapes the ! and echos it into the file
^> escapes the > and echos it into the file