Set Problem

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
john924xps
Posts: 65
Joined: 08 Jun 2012 07:48

Set Problem

#1 Post by john924xps » 27 Sep 2012 05:28

In some snippets of code, I see the set command in use, but this time there are a couple of modifications to it. An example is... observe the code snipped below please...

set "variable=happy"

What's up with the apostrophes? What unique function does it give off? Help? Thanks.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Set Problem

#2 Post by abc0502 » 27 Sep 2012 05:51

Edited:
I removed the answer because it wasn't right, sorry :oops:
Last edited by abc0502 on 27 Sep 2012 06:22, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Set Problem

#3 Post by foxidrive » 27 Sep 2012 06:18

Not quite. SET will happily accept spaces

The surrounding double quotes protect the batch file from any poison characters than can exist in the variable, like & < > | etc
When placed in that position the double quotes themselves are not included in the variable.

This will work too but it adds the double quotes to the variable.
set abc="a 1 2 & 3 > 4 5 6 < zyx"

jeb
Expert
Posts: 1062
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Set Problem

#4 Post by jeb » 27 Sep 2012 07:14

And it has one additional effect.
It safes the assignment for unwanted trailing spaces.

Code: Select all

set "var=value" <SPACE>
Will only set the value to var, the value begins after the equal sign and ends just before at the last quote in the line.
So even this will work

Code: Select all

set "var=value" this will not be assigned

jeb

Post Reply