Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch - Echo or Variable Not Working

I have this little batch script:

SET @var = "GREG" ECHO %@var% PAUSE 

When I run it, it prints:

H:\Dynamics>SET @var = "GREG"  H:\Dynamics>ECHO ECHO is on.  H:\Dynamics>PAUSE Press any key to continue . . . 

Why won't it print the contents of @var? How do I know if @var is even being set?

like image 273
Greg Avatar asked Jun 22 '10 20:06

Greg


People also ask

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.

How do I echo a variable in CMD?

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% ".

What does @echo off do in a batch file?

batch-file Echo @Echo off @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.

What does %% A mean in batch file?

%%a refers to the name of the variable your for loop will write to. Quoted from for /? : FOR %variable IN (set) DO command [command-parameters] %variable Specifies a single letter replaceable parameter. (set) Specifies a set of one or more files. Wildcards may be used.


1 Answers

Dont use spaces:

SET @var="GREG" ::instead of SET @var = "GREG" ECHO %@var% PAUSE 
like image 129
tcooc Avatar answered Oct 13 '22 04:10

tcooc