Windows echo command can't echo a user-set variable Windows echo command can't echo a user-set variable windows windows

Windows echo command can't echo a user-set variable


The set command does not take spaces. The proper syntax would be:

set tt=name

What you have done in your example is set an environment variable tt<space>. With that in mind, you can try this:

echo %tt%

and see your output.


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 osOS=Windows_NTC:\>set tt = nameC:\>set tt2= nameC:\>set tt3=nameC:\>set tttt = namett2= namett3=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.


Have you tried setting the variable with no space between the equals? (set tt=name)