You have two issues. By default group of statements in parens will have variable expansion done all at once, that is before your set
command. Also the semantics for set
is wrong, you don't want spaces around the =
.
Add this to the top of your file:
setlocal ENABLEDELAYEDEXPANSION
and remove the spaces around =
in set
:
set is=%2
Finally used delayed expansion:
echo. !is!
A possible third issue is you may need two SHIFT
s, one for -i
, one for it's is
argument.
Update
Thanks to @dbenham for pointing out that it wasn't a syntax error with set
, it's just surprising behavior that deserves a little explanation. If you execute these commands:
set a=one
echo "%a%"
The result is:
"one"
That makes sense, but try:
set b = two
echo "%b%"
And you get:
"%b%"
What? This is what you would expect when environment var b
is unset. But we just set it. Or did we:
echo "%b %"
Displays:
" two"
For the Windows set
command, unlike any other language or environment I'm aware of, the spaces are significant. The spaces before the =
become part of the environment var name, spaces after become part of the value. This uncommon behavior is a common source of errors when writing Windows batch programs.