经与嵌套的IF麻烦在批处理文件 [英] Having trouble with nested IF in a batch file

查看:123
本文介绍了经与嵌套的IF麻烦在批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对检查出从SVN项目的批处理文件。
我要求用户进入该目录,当你达到你想要的目录,键入结账,并检查出的项目目录。不过,我遇到一些麻烦低于code。请帮助。

I am making a batch file for checking out a project from SVN. I ask the user to enter the directory and when you reach the directory you want, you type checkout and it checks out that project directory. However, I am having some trouble with the code below. Please help.

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
)

我在哪里去错在这里?

Where am I going wrong here?

推荐答案

从不使用:标签也不 ::标签般的评论包含在命令块()括号内。 证明

Never use :label nor :: label-like comment inside a command block enclosed in () parentheses. Proof:

@ECHO %1>NUL
if "" == "" (
    @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 OFF
a simple echo, no comments
a rem comment follows this echo command
a rem comment precedes this echo command
a 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.

==>

下一步code段应按预期工作,如果我能理解你的目标是:

Next code snippet should work as expected, if I can understand your aim:

SETLOCAL enableextensions

rem (set `svnroot_temp` and `choice` variables here)

if /i "%choice%"=="1"  ( 
    cls
    svn ls %svnroot_temp%
    call :top
)
goto :eof

:top
set /p direct=Enter directory:
if /I "%direct%"=="checkout" goto :checkout_area
set "svnroot_temp=%svnroot_temp%\%direct%"
svn ls %svnroot_temp%
goto :top

:checkout_area

请注意,在如果/我直接%%==结账转到相比,两者前pressions:checkout_area 括在双引号中的任何用户输入可能包含空格,甚至可以留空。

不知道在引用的svn ls的%svnroot_temp%

Note that both compared expressions in if /I "%direct%"=="checkout" goto :checkout_area are enclosed in double quotes as any user input could contain a space or even could stay empty.
Not sure about quoting in svn ls "%svnroot_temp%".

不知道是否%svnroot_temp% SVN LS输入或输出目录命令:


  • 在的情况下输入:检查使用,如果不存在%svnroot_temp%\\%直接%\\转到:顶部的通过改变它设置svnroot_temp =%svnroot_temp%\\%直接%

  • 在输出的情况下:使用创建 MD%svnroot_temp%2 - ; NUL 之后的改变它

  • in case input: check it using if not exist "%svnroot_temp%\%direct%\" goto :top before changing it by set "svnroot_temp=%svnroot_temp%\%direct%"
  • in case output: create it using MD "%svnroot_temp%" 2>NUL after changing it.

这篇关于经与嵌套的IF麻烦在批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆