Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
706 views
in Technique[技术] by (71.8m points)

batch-file - 在批处理文件中定义和使用变量(Defining and using a variable in batch file)

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%"

The output I get is the following:

(我得到的输出如下:)

We're working with ""

What's going on here?

(这里发生了什么?)

Why is my variable not being echo'd?

(为什么我的变量没有被回显?)

  ask by Jamie Dixon translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 % .

(因此,您创建的变量可以用%location %引用。)

If that's not what you want, remove the extra space(s) in the definition.

(如果这不是您想要的,请删除定义中的多余空间。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...