Windows 这一行不应出现“错误”isBackup%"==&引用;“是”;
我知道这个问题已经被问过好几次了,但不管出于什么原因,这些答案并没有解决我的问题。下面是违规代码。我正在从.bat文件运行它Windows 这一行不应出现“错误”isBackup%"==&引用;“是”;,windows,batch-file,Windows,Batch File,我知道这个问题已经被问过好几次了,但不管出于什么原因,这些答案并没有解决我的问题。下面是违规代码。我正在从.bat文件运行它 @echo off goto :getSystemID :getSystemID set /p systemId="Please input the System ID - Example 'DD012345-xxxx' : " %=% :getLocation set /p isBackup="Is This a Backup Location? Backup L
@echo off
goto :getSystemID
:getSystemID
set /p systemId="Please input the System ID - Example 'DD012345-xxxx' : " %=%
:getLocation
set /p isBackup="Is This a Backup Location? Backup Locations use 169.254.xxx.x (Y/N) : " %=%
if [/i] "%isBackup%"=="y"
(
set primaryIP = 169.254.xxx.x
goto :end
)
:end
echo %isBackup%
如果直接从.bat或if语句本身运行到命令行中,则会收到相同的错误:
"%isBackup%"=="y" was unexpected at this time.
我所尝试的:
Removed: ""
Removed: [/i]
Changed: [/i] to [/I]
Removed variables: "y"=="y"
我对.bat文件非常陌生,非常感谢您的帮助
用解决方案更新
您可能需要将
(
移动到与if
语句相同的行上。例如:
if "%isBackup%"=="y" (
set primaryIP = 169.254.xxx.x
goto :end
)
而不是:
if "%isBackup%"=="y"
(
set primaryIP = 169.254.xxx.x
goto :end
)
因此,if-else
的一般格式为:
if [condition] (
REM actions to be taken if the condition is true...
) else (
REM actions to be taken if the condition is false...
)
希望有帮助。拆下
/i
语法为if/i操作数1运算符操作数2 somethingtodo
文档中显示的[
。]
表示/i
和非
是可选的
当前,批处理将[/i]
解释为操作数1,将%isBackup%”解释为运算符。它对所使用的运算符表示反对
如果在If
“target”周围使用括号,则(必须与If
类似地,序列)ELSE((如果使用)必须在同一物理行上,就像在FOR
语句中一样。使用测试(在同一行上,但仍然是相同的错误。我感谢您的帮助!是的,没有运气。我还为if语句尝试了一行。如果“%isBackup%”==“y”(set primaryIP=169.254.xxx.x)在这个问题上没有足够的代表,因此无法对您的答案进行投票,但您的答案非常有用!谢谢!我知道这很简单!删除了前面提到的[],并将(移动到与if相同的行)。
if [condition] (
REM actions to be taken if the condition is true...
) else (
REM actions to be taken if the condition is false...
)