China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 11:26
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Problems with the usage of set View 3,117 Replies 5
Original Poster Posted 2006-08-29 23:27 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 48
Joined 2006-06-05 12:53
20-year member
UID 56570
Gender Male
Status Offline
I wrote the following commands with a batch file:
@echo off
set /p a=
if %a%==1 goto 1
if %a%==2 goto 2
goto end
:1
echo 1
goto end
:2
echo 2
:end
The problem is that when entering 1 or 2, the commands are executed respectively, but what if the input is not one of 1 or 2?
So I want to ask, when the other party enters something that is not 1 or 2, how to write this script so that the window displays "No such command"
Thank you!
Floor 2 Posted 2006-08-30 08:33 ·  中国 江苏 苏州 吴中区 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
@echo off
set /p a=
if %a%==1 goto 1
if %a%==2 goto 2
echo No such command
goto end
:1
echo 1
goto end
:2
echo 2
:end
Floor 3 Posted 2006-08-30 18:22 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 48
Joined 2006-06-05 12:53
20-year member
UID 56570
Gender Male
Status Offline
Thanks
Floor 4 Posted 2006-09-03 20:42 ·  中国 广东 东莞 电信
初级用户
我不入地狱谁入地狱
Credits 20
Posts 8
Joined 2006-08-26 15:48
19-year member
UID 61321
Gender Male
Status Offline
What does "set /p a=" represent?
Floor 5 Posted 2012-12-12 15:37 ·  中国 上海 电信
新手上路
Credits 1
Posts 1
Joined 2012-12-06 23:58
13-year member
UID 181055
Gender Male
Status Offline
Learning
Floor 6 Posted 2016-07-30 15:55 ·  中国 湖北 宜昌 电信
新手上路
Credits 11
Posts 6
Joined 2016-07-26 11:18
10-year member
UID 181697
Gender Male
Status Offline
Thanks
Forum Jump: