Batch - If, ElseIf, Else

前端 未结 6 705
谎友^
谎友^ 2021-01-07 18:55

Whats wrong with this code?

IF \"%language%\" == \"de\" (
    goto languageDE
) ELSE (
    IF \"%language%\" == \"en\" (
    goto languageEN
) ELSE (
    ech         


        
6条回答
  •  生来不讨喜
    2021-01-07 19:35

    Recommendation. Do not use user-added REM statements to block batch steps. Use conditional GOTO instead. That way you can predefine and test the steps and options. The users also get much simpler changes and better confidence.

    @Echo on
    rem Using flags to control command execution
    
    SET ExecuteSection1=0
    SET ExecuteSection2=1
    
    @echo off
    
    IF %ExecuteSection1%==0 GOTO EndSection1
    ECHO Section 1 Here
    
    :EndSection1
    
    IF %ExecuteSection2%==0 GOTO EndSection2
    ECHO Section 2 Here
    :EndSection2
    

提交回复
热议问题