I am seeing some strange behavior of a Windows batch script. When PATH
is set
outside an if
block, its value is retained but the value is not retained when set inside the if
block.
Here's a minimal .bat file that shows the problem.
@echo off
echo %*
set PATH=c:\Windows;
set "PATH=c:\Program Files\Siemens\NX 9.0\UGII;%PATH%"
PATH
set "PATH=c:\Program Files\Siemens\NX 9.0\UGII\managed;%PATH%"
PATH
set PATH=c:\Windows;
set arg=%1
if "%arg%" == "a" (
echo "------------------------------------------"
set "PATH=c:\Program Files\Siemens\NX 9.0\UGII;%PATH%"
PATH
set "PATH=c:\Program Files\Siemens\NX 9.0\UGII\managed;%PATH%"
PATH
)
The output of the script when invoked with one a
as the only argument.
a
PATH=c:\Program Files\Siemens\NX 9.0\UGII;c:\Windows;
PATH=c:\Program Files\Siemens\NX 9.0\UGII\managed;c:\Program Files\Siemens\NX 9.0\UGII;c:\Windows;
"------------------------------------------"
PATH=c:\Program Files\Siemens\NX 9.0\UGII;c:\Windows;
PATH=c:\Program Files\Siemens\NX 9.0\UGII\managed;c:\Windows;
As you can see, the directory "c:\Program Files\Siemens\NX 9.0\UGII"
is missing from the last line of output.
Is this expected?
Is there a way to make this work without requiring PATH
to be set only once inside the if
block?