Using variables on the command line

I have a problem using variables on the command line. Based on the value of the environment variable, I want to execute several commands in a batch file. Code 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 scenarios. Therefore, I have little information. Please help me with this.

+4
source share
2 answers

Batch files have a few 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 is important that the brackets are on the same line if , ELSE

+6
source

If you use the variable later, after setting, you will surround the variable with percent signs, for example:

 if %CONFIGURATION% == "release" ... 
0
source

Source: https://habr.com/ru/post/1383823/


All Articles