Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

"/" as parameter separator?

May
13,199
180
I have this alias.
Code:
v:\> alias ipblock
netsh advfirewall firewall add rule name=aablock_%1 dir=in action=block enable=yes localip=any remoteip=%1

If, for example, I do
Code:
ipblock 103.0.0.0/8
the firewall rule gets the name "103.0.0.0" and the remoteip "103.0.0.0/8". Both are understandable; %1 is "103.0.0.0" and %2, which is "/8", is appended to the end.

I also have this plugin function.
Code:
v:\> echo %@IPTOCIDR[58.0.0.0,61.255.255.255]
58.0.0.0/7 60.0.0.0/7

Here's the strange part. If I
Code:
do ip in /L %@IPTOCIDR[58.0.0.0,61.255.255.255] ( ipblock %ip )
the resulting firewall rules have names with the full string (e.g, "58.0.0.0/7").

What's the difference. Here's an actual comparison.
Code:
v:\> ipblock 14.0.0.0/8
Ok.

v:\> netsh advfirewall firewall show rule name=aablock_14.0.0.0/8

No rules match the specified criteria.

v:\> netsh advfirewall firewall show rule name=aablock_14.0.0.0 | grep Name
Rule Name:  aablock_14.0.0.0

v:\> echo %@IPTOCIDR[14.0.0.0,14.255.255.255]
14.0.0.0/8

v:\> do ip in /L %@IPTOCIDR[14.0.0.0,14.255.255.255] ( ipblock %ip )
Ok.

v:\> netsh advfirewall firewall show rule name=aablock_14.0.0.0/8 | grep Name
Rule Name:  aablock_14.0.0.0/8
 
Here's a much simpler example:
Code:
v:\> alias test
echo %1 xx %1

v:\> test a/b
a xx a/b

v:\> do word in /L a/b c/d ( test %word )
a/b xx a/b
c/d xx c/d
 
Hmmm! I thought this had something to do with DO. But it's apparently age-old behavior. Apparently, an alias counts and parses its parameters before any expansion is done on them.
Code:
v:\> alias test
echo %# %1 xx %1

v:\> test a b c
3 a xx a b c

v:\> set word=a b c & test %word
1 a b c xx a b c
 
Back
Top
[FOX] Ultimate Translator
Translate