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?
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.
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% ".
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.
%%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.
Dont use spaces:
SET @var="GREG" ::instead of SET @var = "GREG" ECHO %@var% PAUSE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With