Weird expansion - %:text% and %stripped:text%
Posted: 30 Jun 2011 10:21
Can anyone explain this
My guess is I'll hear from jeb with an "obvious" parsing explanation
Output:
Dave Benham
My guess is I'll hear from jeb with an "obvious" parsing explanation
Code: Select all
@echo off
cls
setlocal disableDelayedExpansion
set :
echo %:Percent expansion is ignored if leading character is a colon%
echo %:Why?%
echo %=Any text:Text through first : is stripped if lead is not :%
setlocal enableDelayedExpansion
echo !:The same is true with delayed expansion!
echo !=Any text:And again%
endlocal
echo Variable name containing : cannot be expanded!
set ":Hello=Goodbye"
set "Hello:World=Goodbye again"
set :
set Hello
echo %:Hello%
echo %Hello:World%
setlocal enableDelayedExpansion
echo !:Hello!
echo !Hello:World!
Output:
Code: Select all
Environment variable : not defined
:Percent expansion is ignored if leading character is a colon
:Why?
Text through first : is stripped if lead is not :
:The same is true with delayed expansion
And again
Variable name containing : cannot be expanded!
:Hello=Goodbye
Hello:World=Goodbye again
:Hello
World
:Hello
World
Dave Benham