This question is a duplicate please do not mark this answer as accepted.
I have posted it to show you an example of using delayed expansion and to offer possible alternatives.
Additionally it shows other best practices which you should use, such as indentation, proper commenting, and the recommended syntax for setting and comparing variables and strings.
@Echo Off
Rem Run command: SO_script.bat DEV PRE 5617295
Rem DEV, TEST or PROD
Set "TypeOfTask=%~1"
Rem PRE, INTER or POST
Set "Process=%~2"
Rem Identification number of investigated task
Set "NoOfTask=%~3"
If "%TypeOfTask%"=="DEV" (
Set "source=C:\ISPPT\TASK\%NoOfTask%"
Set "destination=C:\AutomaticTests\DEV\%NoOfTask%"
SetLocal EnableDelayedExpansion
MD "!destination!" 2>Nul
If "%Process%"=="PRE" (
Copy /Y "!source!\fileA.mod" "!destination!">Nul
)
EndLocal
)
I would also suggest that you add some sort of verification to the script to ensure that it receives all of the required input parameters, in the correct order, and with values matching the acceptable data.
If you're only using the variable names for the purposes of what's shown in your script, you could of course not set any of those variables at all:
@Echo Off
Rem Run command: SO_script.bat DEV PRE 5617295
If "%~1"=="DEV" (
MD "C:\AutomaticTests\DEV\%~1" 2>Nul
If "%~2"=="PRE" (
Copy /Y "C:\ISPPT\TASK\%~1\fileA.mod" "C:\AutomaticTests\DEV\%~1">Nul
)
)
Alternatively you could set the variables before the parenthesised block:
@Echo Off
Rem Run command: SO_script.bat DEV PRE 5617295
Rem DEV, TEST or PROD
Set "TypeOfTask=%~1"
Rem PRE, INTER or POST
Set "Process=%~2"
Rem Identification number of investigated task
Set "NoOfTask=%~3"
Rem Setting source and destination variables
Set "source=C:\ISPPT\TASK\%NoOfTask%"
Set "destination=C:\AutomaticTests\%TypeOfTask%\%NoOfTask%"
If "%TypeOfTask%"=="DEV" (
MD "%destination%" 2>Nul
If "%Process%"=="PRE" (
Copy /Y "%source%\fileA.mod" "%destination%">Nul
)
)