当bat脚本中功能过多,为简化脚本,实现特定功能,可为其增加选择,为特定环境实现不同的选择,减少工作量;效果如图所示:
工具/原料
windows
方法/步骤
1、输出选择项:remthisistoforusertocho艺皱麾酪ose:choiceecho#############垆杪屑丝###################################echo##thisisachoiceexampleecho##choose:echo##A=chooseAecho##B=chooseBecho##C=chooseCecho##D=chooseDecho##q=exit:echo##echo################################################
2、获取终端输入信息:set/Paction=plschooseyouraction:if/I"%action%"=="A"gotoActionA...if/I"%action%"=="q"gotoquit
3、根据终端输入的不同信息,实现不同的动作::ActionAechoyourchoosedAgotochoice...:quitechoexisting..pauseexit
4、美化脚本,最终显示:@echo咯悝滩镞offremthisistoforusertochoose:choiceecho#################垆杪屑丝###############################echo##thisisachoiceexampleecho##choose:echo##A=chooseAecho##B=chooseBecho##C=chooseCecho##D=chooseDecho##q=exit:echo##echo################################################remcheckthechoiceinfoset/Paction=plschooseyouraction:if/I"%action%"=="A"gotoActionAif/I"%action%"=="B"gotoActionBif/I"%action%"=="C"gotoActionCif/I"%action%"=="D"gotoActionDif/I"%action%"=="q"gotoquit:ActionAechoyourchoosedAgotochoice:ActionBechoyourchoosedBgotochoice:ActionCechoyourchoosedCgotochoice:ActionDechoyourchoosedDgotochoice:quitechoexisting..pauseexit