"%systemroot%" chages to "C:\windows"
Moderator: DosItHelp
-
- Posts: 84
- Joined: 08 Sep 2010 10:25
- Location: Iran,Kashan
- Contact:
"%systemroot%" chages to "C:\windows"
I want to save "%systemroot" in C:\copy\jay.bat with batch file
i use it:
echo "%systemroot%" C:\copy\jay.bat"
but changes to C:\WINDOWS
what should i do?
i use it:
echo "%systemroot%" C:\copy\jay.bat"
but changes to C:\WINDOWS
what should i do?
-
- Posts: 84
- Joined: 08 Sep 2010 10:25
- Location: Iran,Kashan
- Contact:
Re: "%systemroot%" chages to "C:\windows"
did not work
Re: "%systemroot%" chages to "C:\windows"
from the command line:
from within a batch file:
Dave Benham
Code: Select all
echo ^%systemroot^%
from within a batch file:
Code: Select all
echo %%systemroot%%
Dave Benham
Re: "%systemroot%" chages to "C:\windows"
Wouldn't one have to use the '>' or the '>>' symbols as well to put into the file?
Re: "%systemroot%" chages to "C:\windows"
dbenham wrote:from the command line:
Code:
echo ^%systemroot^%
from within a batch file:
Code:
echo %%systemroot%%
Within a batch file it's correct.
But from the command line it's only a hack, it isn't bullet proof,
as the caret doesn't escape a percent.
In reallity it only avoids the expansion.
Btw. the first caret is completly useless.
The second caret builds only an undefined variable name, and undefined variables stay unchanged on the command line.
But the carets are removed in the speacial character phase later so the result is
%systemroot%
And the trick fails if there is a variable named systemroot^
Code: Select all
set "systemroot^=fail"
echo ^%systemroot^%
Output wrote:fail
I didn't see a single command solution, only with a helper variable.
Code: Select all
set "helper=systemroot"
echo %%helper%%
jeb
Re: "%systemroot%" chages to "C:\windows"
Wow - I had no idea I had stumbled on a hack.
I knew double percents don't work on the command line like they do in batch mode, and I was curious how to get the result on command line. "Escaping" the percent was the 1st thing I tried and it appeared to work.
It seems like a pretty good hack. I don't recall seeing ^ in a variable name very often.
Excellent explanation of how it actually works. Thanks jeb.
Based on jeb's explanation I realize the hack works if you put the ^ anywhere between the percents (as long as no variable is named that way):
Dave Benham
I knew double percents don't work on the command line like they do in batch mode, and I was curious how to get the result on command line. "Escaping" the percent was the 1st thing I tried and it appeared to work.
It seems like a pretty good hack. I don't recall seeing ^ in a variable name very often.
Excellent explanation of how it actually works. Thanks jeb.
Based on jeb's explanation I realize the hack works if you put the ^ anywhere between the percents (as long as no variable is named that way):
Code: Select all
echo %^systemroot%
echo %system^root%
etc.
Dave Benham
Re: "%systemroot%" chages to "C:\windows"
dbenham wrote:Wow - I had no idea I had stumbled on a hack.
You are not alone
Even Microsoft didn't know it ...
Even the help at reg add /? recommends the hack.
jeb
-
- Posts: 84
- Joined: 08 Sep 2010 10:25
- Location: Iran,Kashan
- Contact: