In one of my scripts, I need to use variables that contain parenthesis inside IF
statements, but either the string is missing a closing parenthesis or the script ex
The )
from the resolved variable in your echo
statement is prematurely closing the IF
block.
Ordinarily, you could fix that by escaping the )
with ^)
, but you can't modify the environment variable to resolve to C:\Program Files (x86^)
.
You can prevent this issue by surrounding the variable with quotes.
As a simpler example:
> SET bad=a)b
> IF 1 == 1 ( ECHO %bad% )
b was unexpected at this time.
> IF 1 == 1 ( ECHO "%bad%" )
"a)b"