we know how to escape special characters like &|<>) with prefxing them with a caret or with enclose them into quotation marks.
Like in
Code: Select all
set "var=Test with &|<>"
or
echo "Test with &|<>
But in the echo example the output will also contain the quote.
Sometimes it would be nice to use quotes, but not to getting them into the result (I call them virtual quotes)

There are two solutions, they are working nearly the same way.
Code: Select all
setlocal EnableDelayedExpansion
echo !"! Test with &|<>
for /f %%^" in ("""") do echo %%~Test with &|<>"
Both use that the parser detects in the special character phase the quotes in !"! or %%~", but later both are removed from the line.
The FOR/F style also works with disabledDelayedExpansion, but it's a bit too long for me,
but you can use it as a macro.
Code: Select all
set "print=for /f %%^" in ("""") do echo(%%~""
%print%Test with &|
This can also be useful, when you create larger macros.
Code: Select all
@echo off
setlocal DisableDelayedExpansion
set LF=^
::Above 2 blank lines are required - do not remove
set ^"\n=^^^%LF%%LF%^%LF%%LF%^^" The normal macro line end with multiline caret
set ^""\n=%%~"^^^%LF%%LF%^%LF%%LF%^^" A macro line end with disappearing quote
set "$"=%%~"" A macro line begin to virtual quote the line
set "CreateMacro=for /f %%^" in ("""") do "
%CreateMacro% set "$testMacro=( for /L %%n in (1 1 2) do echo Hello > out1.txt %"\n%
%$"% echo Also virtual quoted >> out1.txt %"\n%
echo Not quoted ^>^> out1.txt )
echo ------------------------
%$testMacro%
echo ------------------------
hope it helps
jeb