如何在批处理脚本中连接两个变量? [英] how concatenate two variables in batch script?
本文介绍了如何在批处理脚本中连接两个变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在批处理脚本中执行类似的操作.请让我知道这是正确的方法还是可行的方法或其他方法?
I want to do something like this in batch script. Please let me know if this is the proper or possible way to do it or any other way?
set var1=A
set var2=B
set AB=hi
set newvar=%var1%%var2%
echo %newvar%
这应该产生值"hi".
This should produce the value "hi".
推荐答案
启用延迟变量扩展可以解决您的问题,脚本会生成"hi":
Enabling delayed variable expansion solves you problem, the script produces "hi":
setlocal EnableDelayedExpansion
set var1=A
set var2=B
set AB=hi
set newvar=!%var1%%var2%!
echo %newvar%
这篇关于如何在批处理脚本中连接两个变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文