Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

What did I do to screw up my CMD shell? Windows XP Pro, open a cmd window and do:

C:\>set tt = name  C:\>set tt tt = name  C:\>echo %tt% %tt%  C:\>echo %time% 14:13:28.67 

The echo command doesn't work for some reason. I can echo the built-in variables just fine. Tried it on another computer and that works as expected

like image 232
jacobsee Avatar asked Dec 10 '09 21:12

jacobsee


People also ask

How do I echo a variable in Windows command prompt?

To reference a variable in Windows, use %varname% (with prefix and suffix of '%' ). For example, you can use the echo command to print the value of a variable in the form " echo %varname% ".

How do I enable echo in CMD?

To display the command prompt, type echo on. If used in a batch file, echo on and echo off don't affect the setting at the command prompt. To prevent echoing a particular command in a batch file, insert an @ sign in front of the command.

How do I echo a variable in batch file?

Please open a command prompt window, run set /? and read the output help. The syntax is set /P variable=prompt text or better set /P "password=Enter your password: " . And please note that variable password keeps its current value if already defined and user hits just RETURN or ENTER.

Does echo command work on Windows?

Echo is an internal command that is available in the following Microsoft operating systems.


1 Answers

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.

like image 61
akf Avatar answered Oct 05 '22 23:10

akf