在Windows批处理脚本中,我想传递可变数量的参数,然后使用这些参数中的第一个n-1构build一个新variables,并将第n个参数作为另一个variables
所以如果我inputscript.cmd arg1 arg2 arg3 arg4
,我希望能够做到
set newvariable1="arg1 arg2 arg3" set newvariable2="arg4"
如果我inputscript.cmd arg1 arg2 arg3 arg4 arg5 arg6
set newvariable1="arg1 arg2 arg3 arg4 arg5" set newvariable2="arg6"
参数是字母数字string
@echo off setlocal EnableDelayedExpansion set "newvariable1=" set "newvariable2=" for %%a in (%*) do ( set newvariable1=!newvariable1! !newvariable2! set newvariable2=%%a ) set newvariable1="%newvariable1:~2%" set newvariable2="%newvariable2%" echo newvariable1=%newvariable1% echo newvariable2=%newvariable2%