I'm running a batch file which updates some variables, notably %PATH%. My environment has a known bug where on of the directories in %PATH% is quoted, i.e.
PATH=c:\windows;...;"c:\program files\foo"\bin;c:\program files\...
I have a script which appends to PATH. When I do it inside an IF
block, I get an error, e.g:
IF "1"=="1" (
SET "PATH=%PATH%;c:\foo"
)
Gives the error
\Microsoft was unexpected at this time.
Where \Microsoft
is obviously a fragment from one of the directories in %PATH%.
I don't get the error if the SET is not within a conditional block. Why is this?
Edit: It seems that this has more to do with the fact that PATH also contains parenthesis. Here's a better example of the issue:
C:\temp>SET "FOO=C:\Program Files (x86)\;foo"
C:\temp>ECHO %FOO%
C:\Program Files (x86)\;foo
C:\temp>IF "1"=="1" ( ECHO %FOO% )
\ was unexpected at this time.
C:\temp>IF "1"=="1" ECHO %FOO%
C:\Program Files (x86)\;foo
So my question is really, why does it break if it's in the paren-delimited block?