How to escape variables with parentheses inside if-clause in a batch file?

前端 未结 4 2033
天涯浪人
天涯浪人 2020-12-16 10:54

Running this batch file

@echo off
set a=some value with (parentheses) inside
if 1 == 1 (
    set PATH=%a%
)

gives inside was unexpect

4条回答
  •  半阙折子戏
    2020-12-16 11:41

    The ) in %a% is the problem here. You can just do some substitution to escape the ).

    @echo off
    set a=some value with (parentheses) inside
    if 1 == 1 (
        set PATH=%a:)=^)%
    )
    

提交回复
热议问题