Batch Script打印增量数字



下面有一些代码,旨在帮助将choco包自动安装到repo上。

然而,我得到的不是执行命令(正确地回显),而是从数字1开始的一系列数字。

如有任何建议,我们将不胜感激!

参考代码:

@echo off 
set arr[0]=sts
set arr[1]=winscp 
set arr[2]=tortoisegit
set arr[3]=office2013pro  
set arr[4]=notepadplusplusandpm
set arr[5]=git
set arr[6]=GoogleChrome
set arr[7]=jdk
set arr[8]=maven
set "x=0"
:SymLoop  
if defined arr[%x%] (
call set entry=%%arr[%x%]%%
set command=choco install %entry% -y
REM Command isn't running, just prints off numbers
%command%
set /a "x+=1"
GOTO :SymLoop
)

输出如下:

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767777980818288586878909192939596979899100101102103104105106107108110111112113114115117118119120121122123124125127128129130131133134135136138140141142143144145146148149150151152153155156158159160161162163164165166167168169170171172173174175177178179180181182183184185186187188189191192193194196197198199200201203204205207208209210211212213214215216217218220221222223224225226227228230231232233235237239240241242244246247248250251252253254255256258260261262264266267268269270273274275277279280281282283284286288290292294295296297298299300301302303305306307308310311312313314315316317318320321322323324325327328329330331332

@echo off
set arr[0]=sts
set arr[1]=winscp
set arr[2]=tortoisegit
set arr[3]=office2013pro
set arr[4]=notepadplusplusandpm
set arr[5]=git
set arr[6]=GoogleChrome
set arr[7]=jdk
set arr[8]=maven
set "x=0"
:SymLoop
if not defined arr[%x%] goto :EndLoop
call set "entry=%%arr[%x%]%%"
set "command=choco install %entry% -y"
REM Command isn't running, just prints off numbers
%command%
set /a "x+=1"
GOTO :SymLoop
:EndLoop

更改2行,就可以避免使用括号中的代码块。

这有助于避免延迟扩张的需要。需要延迟扩展的示例如set /?所示。

set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "%VAR%" == "after" @echo If you see this, it worked
)

括号之间的所有内容都读取为1个块,并计算一次。因此,括号内的%VAR%不会改变,因为它已经被该值替换。

最新更新