扩展命令提示符的环境变量 [英] Expanding environment variables for command prompt
问题描述
我想运行一个cmd.exe,它将在调用时评估环境变量,而不是在解析命令时。如果我将BASE设置为2并回显它,我应该看到数字2,虽然运行这个脚本没有正确设置基础。
预期行为:
C:\Users\schristo> cmd.exe / X / Cset BASE = 2&&&&&&&&&&& pause
2
按任意键继续。 。 。
实际行为:
C:\Users\ schristo> cmd.exe / X / Cset BASE = 2&&&&&&&&& 。 。
这应该适用于您:
I would like to run a cmd.exe that would evaluate environment variables at call time instead of when it parses the command. If I set the BASE to 2 and echoing it, I should see the number 2, although running this script does not properly set the base. Expected Behavior:
Actual behavior:
This should work for you: 这篇关于扩展命令提示符的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! cmd.exe / X / V:ON / Cset BASE = 2&&& echo!BASE!&&& < / code& / p>
/ V:ON
启用延迟扩展变量,这是您需要的。开关的顺序( / V:ON / C
)很重要。
C:\Users\schristo>cmd.exe /X /C "set BASE=2 && echo %BASE% && pause"
2
Press any key to continue . . .
C:\Users\schristo>cmd.exe /X /C "set BASE=2 && echo %BASE% && pause"
%BASE%
Press any key to continue . . .
cmd.exe /X /V:ON /C "set BASE=2&&echo !BASE!&&pause"
/V:ON
enables Delayed Expansion of variables, which is what you need here. Order of the switches (/V:ON /C
) matters.