Batch file 这个.bat文件的if参数语法有什么问题?
这就是我得到的:Batch file 这个.bat文件的if参数语法有什么问题?,batch-file,Batch File,这就是我得到的: @ECHO OFF IF [%1]==[]( SET /P server=What url would you like to proxy to? : SET /P location=What is the path to your local files? : ) IF [%1]==[ggp]( SET server=10.10.10.10 SET location=c:/Users/Brook/Desktop/hello ) start chrome
@ECHO OFF
IF [%1]==[](
SET /P server=What url would you like to proxy to? :
SET /P location=What is the path to your local files? :
)
IF [%1]==[ggp](
SET server=10.10.10.10
SET location=c:/Users/Brook/Desktop/hello
)
start chrome.exe localhost:8080/login
call:startServer
:startServer
node httpdp.js --server %server% --srcpath %location%
%ifErr% (
call:startServer
)
GOTO:EOF
当if条件被取出时,文件运行良好,因此我的语法有问题,但我不知道
在检查参数是否匹配各种字符串之后,如果有人知道如何做,我实际上想把第一个if条件放在else或default块中
谢谢 这是可行的,但可能还可以改进
@ECHO OFF
IF [%1]==[ggp] GOTO ggp
GOTO default
:ggp
SET server=10.10.10.10
SET location=c:/Users/Brook/Desktop/hello
GOTO always
:default
SET /P server=What url would you like to proxy to? :
SET /P location=What is the path to your local files? :
GOTO always
:always
start chrome.exe localhost:8080/login
call:startServer
:startServer
node httpdp.js --server %server% --srcpath %location%
%ifErr% (
call:startServer
)
GOTO:EOF
这改进了一些语法,使其更加健壮,并停止了子例程的两次调用。未知的命令也会被删除
@ECHO OFF
IF "%~1"=="" (
SET /P server=What url would you like to proxy to? :
SET /P location=What is the path to your local files? :
)
IF /i "%~1"=="ggp" (
SET server=10.10.10.10
SET location=c:\Users\Brook\Desktop\hello
)
start "" chrome.exe localhost:8080/login
call:startServer
goto :EOF
:startServer
node httpdp.js --server %server% --srcpath %location%
REM unknown command %ifErr% ( call:startServer )
GOTO:EOF
谢谢我做什么?第8行中的/i是什么?
%~1
与%1
相同,但如果有双引号,它会删除(一级)周围的双引号。这允许在参数中使用引号或不使用引号。/i
使测试不区分大小写。