简体   繁体   中英

Batch - If Else Goto was unexpected at this time

I know there are better ways of working with a different language. Though I need this done in Batch. Not even powershell. Yes, I know this is 2016. xD

My issue is "Goto Was Unexpected At This Time"

I don't know if this is possible but I am sure it is.

:START_CMD
COLOR 02 & CLS & TITLE COMMAND WINDOW
ECHO. 
SET /P _act=$ || Set _act=za
IF /I [%_act%]==[exit] (
GOTO :LOCK
) ELSE (
IF /I [%_act%]==[lock] (
GOTO :LOCK
) ELSE (
IF /I [%_act%]==[login] (
GOTO :UNLOCK_L1
) ELSE (
IF /I [%_act%]==[path] (
ECHO. & ECHO Current Path: %universalpath% & ECHO. & PAUSE & CLS & GOTO :START_CMD
) ELSE (
IF /I [%_act%]==[check] (
GOTO :HELP
) ELSE (
IF /I [%_act%]==[sudo] (
GOTO :HELP
) ELSE (
IF /I [%_act%]==[report] (
GOTO :SECURITY_LOGIN
) ELSE (
IF /I [%_act%]==[help] (
GOTO :HELP
) ELSE (
IF /I [%_act%]==[whoami] (
GOTO :WHOAMI_NOT_LOGIN
) ELSE (
SET _act=$_act: =%
)

IF /I NOT %_act%==za GOTO :START_CMD
GOTO :START_CMD

Oh, where are the last right brackets?

:START_CMD
COLOR 02 & CLS & TITLE COMMAND WINDOW
ECHO. 
SET /P _act=$ || Set _act=za
IF /I [%_act%]==[exit] (
    GOTO :LOCK
) ELSE (
    IF /I [%_act%]==[lock] (
        GOTO :LOCK
    ) ELSE (
        IF /I [%_act%]==[login] (
            GOTO :UNLOCK_L1
        ) ELSE (
            IF /I [%_act%]==[path] (
                ECHO. & ECHO Current Path: %universalpath% & ECHO. & PAUSE & CLS & GOTO :START_CMD
            ) ELSE (
                IF /I [%_act%]==[check] (
                    GOTO :HELP
                ) ELSE (
                    IF /I [%_act%]==[sudo] (
                        GOTO :HELP
                    ) ELSE (
                        IF /I [%_act%]==[report] (
                            GOTO :SECURITY_LOGIN
                        ) ELSE (
                            IF /I [%_act%]==[help] (
                                GOTO :HELP
                            ) ELSE (
                                IF /I [%_act%]==[whoami] (
                                    GOTO :WHOAMI_NOT_LOGIN
                                ) ELSE (
                                    SET _act=$_act: =%
                                )
                            )
                        )
                    )
                )
            )
        )
    )
)

IF /I NOT %_act%==za GOTO :START_CMD
GOTO :START_CMD

By the way, do you think SET _act=$_act: =% can work? It seems a simple problem, do you think so?

IF /I [%_act%]==[exit] GOTO :LOCK  
IF /I [%_act%]==[lock] GOTO :LOCK  
IF /I [%_act%]==[login] GOTO :UNLOCK_L1  
IF /I [%_act%]==[path] ECHO. & ECHO Current Path: %universalpath% & ECHO. & PAUSE & CLS & GOTO :START_CMD  
IF /I [%_act%]==[check] GOTO :HELP  
IF /I [%_act%]==[sudo] GOTO :HELP  
IF /I [%_act%]==[report] GOTO :SECURITY_LOGIN  
IF /I [%_act%]==[help] GOTO :HELP 
IF /I [%_act%]==[whoami] GOTO :WHOAMI_NOT_LOGIN  
IF /I NOT [%_act%]==[za] GOTO :START_CMD  
GOTO :START_CMD  

This works just as well, and is more efficient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM