0

我正在尝试做这样的事情:

@echo off

:beginning
choice /c:123
if %errorlevel%== 1 set test= aaa
if %errorlevel%== 2 set test= bbb
if %errorlevel%== 3 set test= ccc
call :%test%one
pause
goto beginning

:aaaone
echo phrase
exit /b

:bbbone
echo phrase
exit /b

:cccone
echo phrase
exit /b

我正在尝试调用 :%test%one 来调用任何错误级别的输出,但它不会识别 %test% 的变量“test”的输出,并说它找不到标签。有没有办法让用户选择程序调用的内容,而不仅仅是使用“goto(标签)”?提前感谢您提供的任何建议。

4

2 回答 2

3

您需要在这些行中删除 = 之后的空格:

if %errorlevel%==1 set test=aaa
if %errorlevel%==2 set test=bbb
if %errorlevel%==3 set test=ccc
于 2013-11-06T03:24:36.557 回答
1

您也可以使用不同的、更简单的形式,如下所示:

@echo off

:beginning
choice /c:123
call :%errorlevel%one
pause
goto beginning

:1one
echo phrase
exit /b

:2one
echo phrase
exit /b

:3one
echo phrase
exit /b
于 2013-11-06T05:53:25.537 回答