Reputation: 1135
I have a problem in using variables in command prompt. Based on the value of the environment variable, i want to execute a few commands in a batch file. The code is below:
SET CONFIGURATION=Release
if "CONFIGURATION"=="Release"
(copy c:\python26\test1.py d:\testfiles
copy c:\case.jpg d:\images
)
else
(copy c:\python26\test2.py d:\testfiles
copy c:\debug.jpg d:\images
)
This is what I want to do. I am new to using these kind of scripts. So I don't have much information. Please help me with this.
Upvotes: 4
Views: 17541
Reputation: 82307
Batch files have a somewhat special syntax
So your code should look like
SET CONFIGURATION=Release
if "%CONFIGURATION%"=="Release" (
copy c:\python26\test1.py d:\testfiles
copy c:\case.jpg d:\images
) else (
copy c:\python26\test2.py d:\testfiles
copy c:\debug.jpg d:\images
)
It's important, that the brackets are on the same line of if
, ELSE
Upvotes: 6
Reputation: 2159
When using the variable later, after set, you will surround the variable with percent signs, like so:
if %CONFIGURATION% == "release" ...
Upvotes: 0