I never said that, so I'm not sure why you are reaching that conclusion.
Of course both forms pass through phase 2.
My original explanation attempts to show a command, and then illustrate the intermediate result of each phase.
And here is an example of what I intended in my last post:
Code: Select all
@echo off
setlocal disableDelayedExpansion
set "^=(ExpandedCaret)"
set "str1=!^^!-"!^^!""
set "str2=^^!^^^^^^!-"^^!^^^^^^!""
:: Show values of variables
set ^^
set str
:: Show command that we are evaluating by doubling all % and doubling all unquoted ^
echo Evaluating: echo ExpandedInPhase1:%%^^%% ExpandedInPhase5:%%str1%% NotExpanded:%%str2%%
:: Show result of Phases 1 and 2
echo AfterPhases1and2: ExpandedInPhase1:%^% ExpandedInPhase5:%str1% NotExpanded:%str2%
setlocal enableDelayedExpansion
:: Result of phases 1 and 2 the same, so difference shows result of phase 5
echo AfterPhases1,2,5: ExpandedInPhase1:%^% ExpandedInPhase5:%str1% NotExpanded:%str2%
--OUTPUT--
Code: Select all
^=(ExpandedCaret)
str1=!^^!-"!^!"
str2=^^!^^^^^^!-"^!^^^!"
Evaluating: echo ExpandedInPhase1:%^% ExpandedInPhase5:%str1% NotExpanded:%str2%
AfterPhases1and2: ExpandedInPhase1:(ExpandedCaret) ExpandedInPhase5:!^!-"!^!" NotExpanded:^!^^^!-"^!^^^!"
AfterPhases1,2,5: ExpandedInPhase1:(ExpandedCaret) ExpandedInPhase5:(ExpandedCaret)-"(ExpandedCaret)" NotExpanded:!^!-"!^!"
Remember, there is escaping happening in both phases 2 and 5, which is why str1 and str2 are defined the way they are.
To preserve ^ literal in phase 2 you need "^" if quoted, and ^^ if not quoted. A ! literal just needs itself in phase 2.
To preserve ^ literal in phase 5 you need ^^ and ! literal requires ^!, regardless whether the strings are quoted or not.
But the string must pass through phase 2 before it gets to phase 5. So unquoted ^ and ! require ^^^^ ^^! and quoted requires "^^ ^!"
Here is effectively the same test, but without using the intermediate str1 and str2 variables:
Code: Select all
@echo off
setlocal disableDelayedExpansion
set "^=(ExpandedCaret)"
:: Show values of variables
set ^^
:: Show command that we are evaluating by doubling all % and doubling all unquoted ^
echo Evaluating: echo ExpandedInPhase1:%%^^%% ExpandedInPhase5:!^^^^!-"!^!" NotExpanded:^^^^!^^^^^^^^^^^^!-"^!^^^!"
:: Show result of Phases 1 and 2
echo AfterPhases1and2: ExpandedInPhase1:%^% ExpandedInPhase5:!^^!-"!^!" NotExpanded:^^!^^^^^^!-"^!^^^!"
setlocal enableDelayedExpansion
:: Result of phases 1 and 2 the same, so difference shows result of phase 5
echo AfterPhases1,2,5: ExpandedInPhase1:%^% ExpandedInPhase5:!^^!-"!^!" NotExpanded:^^!^^^^^^!-"^!^^^!"
--OUTPUT--
Code: Select all
^=(ExpandedCaret)
Evaluating: echo ExpandedInPhase1:%^% ExpandedInPhase5:!^^!-"!^!" NotExpanded:^^!^^^^^^!-"^!^^^!"
AfterPhases1and2: ExpandedInPhase1:(ExpandedCaret) ExpandedInPhase5:!^!-"!^!" NotExpanded:^!^^^!-"^!^^^!"
AfterPhases1,2,5: ExpandedInPhase1:(ExpandedCaret) ExpandedInPhase5:(ExpandedCaret)-"(ExpandedCaret)" NotExpanded:!^!-"!^!"
I hope the above makes things clearer. I don't have any more explanation to give you. I understand this is complicated. It has taken me years to develop my understanding.
Dave Benham