Using double quotes when setting variables

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ldoodle
Posts: 18
Joined: 26 Sep 2015 04:01

Using double quotes when setting variables

#1 Post by ldoodle » 01 Oct 2015 04:12

Is there a best practice as to when variables should be enclosed like set "var=val"

Is it the case that if val contains spaces, enclose it, unless it's using a delayed expansion value:

set "var1=Hello world"
set var2=!var!

?

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

Re: Using double quotes when setting variables

#2 Post by foxidrive » 01 Oct 2015 05:12

Your previous posts and code which you solved with double quotes has been removed,
and the answer here is that you can always use double quotes when setting a variable
- they are not part of the variable itself.

If the variable contains double quotes and especially unbalanced double quotes then the best solution depends on the exact details of the situation.



set "var1=Hello world"
set "var2=!var!"

Post Reply