I've read this post, which helps in most cases, and this post, which seems a duplicate, but I couldn't get it to work.
Disclaimer: disabling/enabling delayed expansion works as workaround but that's annoying to do, unless the whole script can be disabled. I am curious whether there's a more direct approach.
I use this brilliantly simple colorEcho script and sometimes I just want to print an exclamation mark. As that post shows (but fails to address), it doesn't print the exclamation mark.
Repro:
@echo Off
SETLOCAL EnableDelayedExpansion
rem Initialize backspace-space-backspace
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
rem Using it
call :colorEcho 0a "Give me an exclamation!"
echo.
pause
GOTO :EOF
rem The actual color-print hack
:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i
Gives:
I've tried:
call :colorEcho 0A "Ex^!"
and variants like^^^!
- first
set excl=^^!
thenCALL :colorEcho "Foo!excl!"
- some variants with more/less escaping
created a simplified routine without
colorEcho
, but it ran into the same issues::test rem How to call :test with %1 containing an excl mark echo %1 exit /B
Perhaps this is not possible, and I should either not want to output an exclamation mark, or I should use the already mentioned DisableDelayedExpansion
. Any ideas?