I would suggest the following only as a comment, but I think it is important enough to stand on my own.
Many previous answers mentioned that you need to beware of lagging spaces; and that's for sure. However, I found that sometimes trailing spaces just want to get there no matter what is especially important if you are running a single-line command line interface and need space as a command separator.
This is the solution to this problem:
SET FOO=Bar echo %FOO% :: outputs Bar SET "FOO=" echo %FOO% :: outputs %FOO%
By wrapping the ad in double quotation marks this way, the span issue can be completely eliminated. It can also be very useful when variables are created by concatenating to eliminate spaces between them - for example - paths, for example:
SET A=c:\users\ && SET D=Daniel SET P="%a%%d%" ECHO %P% :: outputs "C:\Users\ Daniel" :: Notice the undesirable space there
user1167442 Dec 01 '16 at 16:15 2016-12-01 16:15
source share