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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ZALEK
Posts: 1
Joined: 09 Aug 2011 13:35

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

#1 Post by ZALEK » 09 Aug 2011 13:48

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

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

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

#2 Post by Ed Dyreen » 09 Aug 2011 15:02

'
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.

Acy Forsythe
Posts: 126
Joined: 10 Jun 2011 10:30

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

#3 Post by Acy Forsythe » 09 Aug 2011 16:35

@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 :)

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

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

#4 Post by Ed Dyreen » 09 Aug 2011 16:53

'
You got me Acy :P I completely missed that :roll:

Post Reply