本文介绍了在批处理文件中定义和使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在批处理文件中定义和使用变量.看起来应该很简单:

I'm trying to define and use a variable in a batch file. It looks like it should be simple:

@echo off

set location = "bob"
echo We're working with "%location%"

我得到的输出如下:

We're working with ""

这是怎么回事?为什么我的变量没有被回显?

What's going on here? Why is my variable not being echo'd?

推荐答案

=之前的空格被解释为名称的一部分,而其后的空格(以及引号)也被解释为名称的一部分.价值.因此,您创建的变量可以用%location %引用.如果这不是您想要的,请删除定义中的多余空格.

The space before the = is interpreted as part of the name, and the space after it (as well as the quotation marks) are interpreted as part of the value. So the variable you’ve created can be referenced with %location %. If that’s not what you want, remove the extra space(s) in the definition.

这篇关于在批处理文件中定义和使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 18:03