开发者

Why does my if Else if statement not work in Batch script?

开发者 https://www.devze.com 2023-04-12 11:15 出处:网络
My Script echo \"Enter your choice (1 or 2 or 3) :\" set /p dbchoice= IF %dbchoice EQU 1 ( set dbtype=\"oracle\"

My Script

echo "Enter your choice (1 or 2 or 3) :"
set /p dbchoice=

IF %dbchoice EQU 1 ( 
    set dbtype="oracle"
) ELSE ( 
    IF %dbchoice EQU 2 ( 
        set dbtype="sqlserver" 
    )
) ELSE ( 
    IF %dbchoice EQU 3 ( 
        set dbtype="db2" 
  开发者_JS百科  )
) ELSE (
    echo "Incorrect choice" 
)

I get the following output:

E:\csmilm>set /p dbchoice=
1
ELSE was unexpected at this time.
E:\csmilm>) ELSE (
E:\csmilm>

What is the problem here?


Closing brackets in the wrong place. Try:

IF %dbchoice EQU 1 ( 
    set dbtype="oracle"
) ELSE ( 
    IF %dbchoice EQU 2 ( 
        set dbtype="sqlserver" 
    ) ELSE ( 
        IF %dbchoice EQU 3 ( 
            set dbtype="db2" 
        ) ELSE (
            echo "Incorrect choice" 
        )
    )
)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号