Hi Dave,
yes, in phase 2 the command token and the parameters are determined, therefore the escaping plays a role. but not for the splitting of the parameters (perhaps in pahse7 ?)
It's also important for the delayed expansion phase, as this phase is executed indipendent for the command and the parameter token.
Code: Select all
setlocal EnableDelayedExpansion
echo^ Remove^ caret"^"-^ by^ delayed^ expansion^ ! But not in the parameter "^"
echo^ Remove^ caret"^"-^ by^ delayed^ expansion ! NOW in the parameter "^"
Output wrote:Remove caret""- by delayed expansion But not in the parameter "^"
Remove caret"^"- by delayed expansion NOW in the parameter ""
The command token in phase2 is used to detect the special internal commands IF, FOR, REM. ( REM is special special!)
Therefore this fails
Code: Select all
IF^ 1==1 echo TRUE
FOR^ %%A in (*) do echo
REM^ /?
But there has to be another splitting in phase 7 (Phase 7-B), else it wouldn't be possible to execute/detect executables or internal commands.
This splitting is done if no external command with the "full name" can't be found.
But even then a second search is done.
Code: Select all
@echo off
setlocal EnableDelayedExpansion
del "echo .bat"
del "echo.bat .bat"
echo^ .bat #1 hello
echo echo #2 THIS IS %%~0 > "echo .bat"
REM echo echo #3 THIS IS %%~0 > "echo.bat .bat"
echo.bat^ .bat #4 hello
Output wrote:.bat #1 hello
bat .bat #4 hello
Code: Select all
@echo off
setlocal EnableDelayedExpansion
del "echo .bat"
del "echo.bat .bat"
echo^ .bat #1 hello
echo echo #2 THIS IS %%~0 > "echo .bat"
echo echo #3 THIS IS %%~0 > "echo.bat .bat"
echo.bat^ .bat #4 hello
Output wrote:.bat #1 hello
#3 THIS IS echo.bat .bat
With your other post, I assume that the delayed expansion is only executed in the Phase7-B.
Code: Select all
setlocal DisableDelayedExpansion
set "myFile=other"
(
echo setlocal DisableDelayedExpansion
echo echo THIS is %%~f0 args=%%*
) > other.bat
setlocal EnableDelayedExpansion
!myFile!.bat Hello"^"!
Output wrote:
THIS is c:\temp\empty\other.bat args=Hello""
But with only phase 7-A
Code: Select all
@echo off
setlocal DisableDelayedExpansion
set "myFile=other"
del !myFile!.bat 2>nul
(
echo setlocal DisableDelayedExpansion
echo echo THIS is %%~f0 args=%%*
) > !myFile!.bat
(
echo setlocal DisableDelayedExpansion
echo echo THIS is %%~f0 args=%%*
) > other.bat
setlocal EnableDelayedExpansion
!myFile!.bat Hello"^"!
Output wrote:
THIS is c:\temp\empty\!myFile!.bat args=Hello"^"!
If the command tokens wasn't handled by delayed expansion (Phase 7-B), then the parameters are also not handled