扩展命令提示符的环境变量 [英] Expanding environment variables for command prompt

查看:107
本文介绍了扩展命令提示符的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个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&&&&&&&&& 。 。

解决方案

这应该适用于您:



cmd.exe / X / V:ON / Cset BASE = 2&&& echo!BASE!&&& < / code& / p>

/ V:ON 启用延迟扩展变量,这是您需要的。开关的顺序( / V:ON / C )很重要。


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: C:\Users\schristo>cmd.exe /X /C "set BASE=2 && echo %BASE% && pause" 2 Press any key to continue . . .

Actual behavior: C:\Users\schristo>cmd.exe /X /C "set BASE=2 && echo %BASE% && pause" %BASE% Press any key to continue . . .

解决方案

This should work for you:

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.

这篇关于扩展命令提示符的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆