Parenthesis in variables inside IF blocks

后端 未结 5 1023
天命终不由人
天命终不由人 2021-02-07 12:12

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

5条回答
  •  我在风中等你
    2021-02-07 13:00

    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"
    

提交回复
热议问题