Batch file (此时出现意外情况。)

Batch file (此时出现意外情况。),batch-file,Batch File,在批处理中运行此操作时,我得到了一个“(此时是意外的)”错误。为什么?我用引号括住了变量和变量的值。y后面有一个空格,然后是括号 echo Would you like to update and restore to the latest OS? (-l -e) (Y/N) set /p latestOS= "" if "%latestOS%"=="y" ( echo Restoring...make sure your device is plugged in! \idevicere

在批处理中运行此操作时,我得到了一个“(此时是意外的)”错误。为什么?我用引号括住了变量和变量的值。y后面有一个空格,然后是括号

echo Would you like to update and restore to the latest OS? (-l -e) (Y/N)

set /p latestOS= ""

if "%latestOS%"=="y" (

echo Restoring...make sure your device is plugged in!

\idevicerestore\idevicerestore -l -e

echo Done.

timeout /t 2 /nobreak > NUL

) else (

    echo Okay. Where is the IPSW located? EX: C:\memez.ipsw

    set /p IPSWlocid= ""

    echo Alright. Is it a custom IPSW? Note that the device must be vulnerable to limera1n. (-c) (Y/N)

    set /p IPSWiscustomid= ""

    rem more stuff soon

)

:menu

它在if latestOS行失败。

您的代码有几个问题,包括在第一个
echo
语句中使用了括号,没有被引用或转义,在
=
登录
set/p
行后有一个空格。不过,您的代码可以简单得多。我不打算一一说明,但是这里有一些相关的改变可以帮助你

@echo off
set /p latestOS="Would you like to update and restore to the latest OS? (-l -e) (Y/N): "

if "%latestOS%"=="y" (
  echo You chose Yes
) else (
  echo You chose No
)

当您有一个代码块(即括号内的代码)时,batch会将第一个未转义的
视为该块的结尾,而不管它位于代码块中的什么位置

else
块内部的第二个
echo
正在破坏您的代码。若要修复它,请使用
^
来转义这两个


Stil失败,但随后出现了另一个错误。显然,第一条回音线中的括号把事情搞糟了。谢谢
echo Alright. Is it a custom IPSW? Note that the device must be vulnerable to limera1n. (-c^) (Y/N^)