在DOS中如何抑制环境变量扩展? [英] How do you suppress environment variable expansion within DOS?
问题描述
这是一个简单的例子,修改了我想要做的变量名称。为了简单起见,我正在显示命令行版本而不是bat文件版本。
This is a simplified example with modified variable names of what I want to do. Also for simplicity sake, I am showing the command line version rather than the bat file version.
我正在做以下操作。
> echo %foo%
%foo%
但是,如果foo是有效的环境变量,由于环境变量扩展,我不会得到期望的输出(%foo%)。
However, if foo is a valid environment variable, I do not get desired output (%foo%) due to environment variable expansion.
> set foo=bar
> echo %foo%
> echo %%foo%%
bar
%bar%
现在,我有一个黑客(以下示例),但我想知道是否有一个更干净的方法来输出一个'%'字符或抑制环境变量扩展。
Now, I have a hack to do (following example) this but I was wondering if there is a cleaner way to either output a '%' character or to suppress environment variable expansion.
> set foo=bar
> set percent=%
> echo %percent%foo%percent%
%foo%
此外,如果所需的解决方案在bat文件中不同(如%%而不是%或%1%而不是%1)请让我知道。
Also, if the required solution is different in a bat file (like %% rather than % or %1% rather than %1) please let me know.
我的实际用例在与SETX的蝙蝠文件中设置依赖另外一个环境变量的全局环境变量来扩展它们。
My actual use case is in a bat file with SETX to set global environment variables that rely on another environment variable to be expanded within them.
推荐答案
一个批处理文件echo %% foo %%将生成%foo%。
in a batch file, echo %%foo%% will generate %foo%.
c:\01Temp>type foo.bat
@echo %%foo%%
c:\01Temp>foo
%foo%
c:\01Temp>
这篇关于在DOS中如何抑制环境变量扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!