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

Categories

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

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

1 Answer

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...