Echo command and environment variable
Moderator: DosItHelp
Echo command and environment variable
HI
Using the echo command of Windows 7 SP1, how can I insert, in a text file, an environment variable (like %WINDIR%) without that it is first interpreted by the shell?
THANKS
BYE
Using the echo command of Windows 7 SP1, how can I insert, in a text file, an environment variable (like %WINDIR%) without that it is first interpreted by the shell?
THANKS
BYE
Re: Echo command and environment variable
It not works. Why?
THANKS
BYE
Re: Echo command and environment variable
It depends of the context.
If you want do it from a batch file then the solution of miskox works.
But from the cmd shell it doesn't work the same way.
There doesn't exist an escape possibility, but you can use a workaround.
jeb
If you want do it from a batch file then the solution of miskox works.
But from the cmd shell it doesn't work the same way.
There doesn't exist an escape possibility, but you can use a workaround.
Code: Select all
echo %^windir%>outputfile.txt
or
echo %windir^%>outputfile.txt
or
echo %win^dir%>outputfile.txt
jeb
Re: Echo command and environment variable
what miskox said is right but remove one of the % like that
echo %windir% >>outputfile.txt
Re: Echo command and environment variable
Not really, it can only work if windir isn't defined.
Try it with
And it will fail
Try it with
Code: Select all
echo %path%
And it will fail
Re: Echo command and environment variable
If you are using a CMD prompt then please say so, otherwise we will assume you are using batch files, where the command above works fine.
Re: Echo command and environment variable
I hope that I understand you.
You will not write the value of the variable %WINDIR% in the file.
You will write %WINDIR% in the file.
The result is:
You will not write the value of the variable %WINDIR% in the file.
You will write %WINDIR% in the file.
Code: Select all
ECHO The windows folder will you find in ^%WINDIR^%.>outputfile.txt
The result is:
- The windows folder will you find in %WINDIR%.
Re: Echo command and environment variable
@trebor68: As I said before, the caret doesn't escape a percent sign, it's only a workaround that will work often, but not always.
A secure way will be
A secure way will be
Code: Select all
for %Y in ("%") do echo %~Ywindir%~Y