批处理文件中嵌套的IF有麻烦

我正在制作一个批处理文件,用于从SVN中签出项目。我要求用户输入目录,当您到达所需的目录时,键入checkout,它将签出该项目目录。但是,我在下面的代码上遇到了一些麻烦。请帮忙。


if /i %choice%==1  ( 

cls

svn ls %svnroot_temp%

:top

set /p direct=Enter directory:

if %direct%=checkout( goto :checkout_area )

set svnroot_temp= %svnroot_temp%/%direct%

svn ls %svnroot_temp%

goto :top

)

我在哪里错了?


RISEBY
浏览 820回答 1
1回答

慕姐4208626

从来没有使用:label也没有:: label-like comment封闭在命令块内部()的括号。证明:@ECHO %1>NULif "" == "" (    @echo a simple echo, no comments)if ""=="" (  @echo a rem comment follows this echo command  rem comment  @echo a rem comment precedes this echo command)if ""=="" (  @echo a label-like comment follows this echo command  :: comment  @echo a label-like comment precedes this echo command)if ""=="" (  @echo a label follows this echo command  :label  @echo a label precedes this echo command)输出:==>D:\bat\labels.bat OFFa simple echo, no commentsa rem comment follows this echo commanda rem comment precedes this echo commanda label-like comment follows this echo command'@echo' is not recognized as an internal or external command,operable program or batch file.a label follows this echo command'@echo' is not recognized as an internal or external command,operable program or batch file.==>如果我可以理解您的目标,那么下一个代码段应该可以按预期工作:SETLOCAL enableextensionsrem (set `svnroot_temp` and `choice` variables here)if /i "%choice%"=="1"  (     cls    svn ls %svnroot_temp%    call :top)goto :eof:topset /p direct=Enter directory:if /I "%direct%"=="checkout" goto :checkout_areaset "svnroot_temp=%svnroot_temp%\%direct%"svn ls %svnroot_temp%goto :top:checkout_area请注意,两个比较表达式if /I "%direct%"=="checkout" goto :checkout_area都用双引号引起来,因为任何用户输入都可能包含空格,甚至可能为空。不确定要引用svn ls "%svnroot_temp%"。不确定命令"%svnroot_temp%"的输入目录还是输出目录svn ls:如果输入:if not exist "%svnroot_temp%\%direct%\" goto :top 在更改之前先检查使用set "svnroot_temp=%svnroot_temp%\%direct%"万一输出:更改MD "%svnroot_temp%" 2>NUL 后使用创建。
打开App,查看更多内容
随时随地看视频慕课网APP