批处理文件如果错误
问题描述:
好了,所以我工作的一个项目,我这样做,我得到的confirmOne if语句,它给了我“(预计不会在这个时候。”请帮帮忙!批处理文件如果错误
许多流浪的“你到了这里!”的消息是我试图调试它的,我很快就需要这个,请帮忙,我也尝试删除零件,但它似乎仍然不起作用,如果你看到其他错误请告诉我,我需要的所有帮助我可以得到的。谢谢!
:grabInput
echo Please enter the username of the user you wish to access.
REM - } End Echoing Information/Main Menu | Grab Input {
set /p result=
goto correctName
REM - } End Grab Input | Process Input {
:correctName
set /p input=%result%
goto confirmOne
:confirmOne
echo Got to confirmOne
pause
if %input%==[] (
pause
cls
echo Oops! Looks like you didn't enter anything! Try Agian!
echo.
echo ................................................................................
echo.
goto grabInput
) ELSE (
goto confirmTwo
)
:confirmTwo
echo Got to ConfirmTwo
pause
if %input%==~help (
goto helpMenu
) ELSE (
goto confirmThree
)
:confirmThree
echo Got to ConfirmThree
if %input%==~info (
goto infoMenu
) ELSE (
goto swapDrive
)
答
好吧,如果你没有为%input%
输入任何内容,那么你的if
语句应该丽ke if ==[] (
。
你if
语句应该看起来像if [%input%] == [] (
我也看到了很多不必要的代码,你应该看看在你的脚本。
答
批总是作品的字符串。
的发言if %input%==[]
,当输入%%设定为[无](这是你想要什么检测),批量替代品[无] FO %input%
,并得到
IF ==[] (
,是困惑因为'('不是比较运算符。
[]
不是一些魔法咒语,它是一种检测参数存在的旧方法,如果参数缺失,[%1]将等于[],它不会' t当变量包含空格或其他字符时工作。
if "%var%"=="" is better
if not defined var is better still
注意
set /p var=
不会将var
为[无]你只需按下enter
,它会留下var
不变。
因此,这
set var=something
set /p var=
将离开var
设置为something
。您应该
set "var="
set /p var="Some prompt "
if not defined var echo VAR is not defined
这个代码的引号var=
确保var
未设置为[一些空间]如果有就行了尾部的空格。
除此之外,序列
goto somelabel
:somelabel
(REM线是不相关的)是多余的。
同样,在
if somecondition (goto somewhere) else (goto somewhereelse)
:somewhereelse
的else
条件是多余
批次仅通知:label
作为用于GOTO
或CALL
的目的地。否则将直接通过它发现的任何:label
直接收费,就好像它们是评论声明一样。
非常感谢! – user2263904 2013-04-10 21:46:25