The most upvoted answer here, accepted far ago, claims that:
"The set
command does not take spaces."
But that is not correct: The %tt %
variable actually works: It can be set and referenced. (Despite it is confusing.)
Problem reproduced:
Indeed, on my Win7:
C:\>set os
OS=Windows_NT
C:\>set tt = name
C:\>set tt2= name
C:\>set tt3=name
C:\>set tt
tt = name
tt2= name
tt3=name
I tried and got:
C:\>echo "%os%"
"Windows_NT"
C:\>echo "%tt3%"
"name"
C:\>echo "%tt2%"
" name"
C:\>echo "%tt%"
"%tt%"
Resolved cases:
The intuitively expected variable %tt%
is not set. But %tt %
is set instead:
C:\>echo "%tt %"
" name"
Even more, with a space at the end of the value, set tt4 = name
:
C:\>echo "%tt4 %"
" name "
Conclusions:
The set
command does not trim()
:
- The space before "=" is included to the
var_name
.
- The space after "=" is included to the
var_value
.
- The space at the end of the
var_value
is included to it.
On the other hand:
- The space at the beginning of the
var_name
is not included to it, which is rather normal for command line arguments in general.