我有一个批处理文件,最后有一个函数定义。事实上,我知道函数是问题所在,因为当它到达对函数或定义本身的任何调用时,错误就会返回。我收到错误:the syntax of the command is incorrect.
我检查了括号嵌套是否有错误,但无济于事。Batch 是否允许我向参数请求if defined
语句并在其内部调用函数?
除此之外,我似乎无法解决错误。
rem Functions.
:checkLvl
if "%~1" EQU "%~2" (
set counter=0
if defined %~3 echo %~3
if defined %~4 echo 1: %~4 &&set counter=1
if defined %~5 echo 2: %~5 &&set counter=2
if defined %~6 echo 3: %~6 &&set counter=3
if defined %~7 echo 4: %~7 &&set counter=4
if defined %~4 (
set /p checkChoice=
if defined !checkChoice! (
if !checkChoice! GTR 0 (
if !checkChoice! LEQ !counter! (
set checkChoice=!checkChoice!
) else (
echo Enter a value below or equal to !counter! and greater than 0.
set checkChoice=null
call:checkLvl %~1 %~2 %~3 %~4 %~5 %~6 %~7
)
) else (
echo Enter a proper value.
set checkChoice=null
call:checkLvl %~1 %~2 %~3 %~4 %~5 %~6 %~7
)
) else (
echo Enter a value (1-!counter!).
set checkChoice=null
call:checkLvl %~1 %~2 %~3 %~4 %~5 %~6 %~7
)
)
set returnCheck=true
) else ( set returnCheck=false )
goto:eof