Page 1 of 1

What does it means: SET %~1=!%1:b=B!

Posted: 09 Aug 2011 13:48
by ZALEK
I found a code which converts lower cases to upper cases, but have no idea how to interpret the code:
SET %~1=!%1:b=B!
I know it changes in variable %1 character b to B, but I don't uderstand how it is related to the SET command.

I found explanation for "SET %PATH:str1=str2%" - but this is not the same.
Where I can find explanation for SET %~1=!%1:b=B!

Thanks,

Zalek

Re: What does it means: SET %~1=!%1:b=B!

Posted: 09 Aug 2011 15:02
by Ed Dyreen
'
I'll decompile a similar command into it's elements

Code: Select all

for %%! in ( !ALPHABET.LCASE! ) do set "$=!$:%%!=%%!!"
::
for %%! in ( a b c d e f g h i j k l m n o p q r s t u v w x y z ) do set "$=!$:%%!=%%!!"
::
for %%! in ( a ) do set "$=!$:%%!=%%!!"
::
set "$=!$:A=a!"
We are taking advantage of the fact that set is case insensitive.
But this particular code depends on delayed expansion, try this:

Code: Select all

@echo off
set "$Var=HELLO"
set "$Var=%$Var:l=l%"
set "$Var=%$Var:e=e%"
set "$Var"
pause
exit /b
%~1 is the first parameter that was passed, %~2 the 2nd etc... %~0 is your batch in question, %* is entire input.

Re: What does it means: SET %~1=!%1:b=B!

Posted: 09 Aug 2011 16:35
by Acy Forsythe
@Ed,

I think part of the problem is that his Example is wrong. It's not SET %PATH:str1=str2%...

It should be SET PATH=%PATH:str1=Str2% and then it not only works, but it also mimics his example question:

Code: Select all


SET PATH=%PATH:str1=Str2%

SET %~1=!%1:str1=str2!



Now the only difference is the ! being used for delayed expansion and the ~ being used to remove quotes.

The explanation of ~ can be found in both SET /? at the end and CALL /?

The explanation of ! used for delayed expansion can be found in SET /? and FOR /?

If you want, you can paste the full code you're referring to and I will attempt to explain it and Ed will correct me when I am wrong :)

Re: What does it means: SET %~1=!%1:b=B!

Posted: 09 Aug 2011 16:53
by Ed Dyreen
'
You got me Acy :P I completely missed that :roll: