Answers:
例如,如果要跳过前三个参数,然后传递其余参数:
@echo off
for /f "tokens=1-3*" %%a in ("%*") do (
set par1=%%a
set par2=%%b
set par3=%%c
set therest=%%d
)
call other.bat %therest%
参数中的引号可能存在问题。
帕特里克·库夫(Patrick Cuff)的荣誉,https://stackoverflow.com/questions/382587/how-to-get-batch-file-parameters-from-nth-position-on
您可以将示例编写如下:
@echo off
call other.bat %*
另外:移支持Windows ...查看此。
但是确实,最后一个链接确认了shift与%*结合使用无效:
•使用*%与移
移已经没有在%。*批次参数的影响。
@echo off
cls
setlocal enabledelayedexpansion
:: Disable the display of information by changing [set "_ENABLE_INFO="] to [set "_ENABLE_INFO=::"].
set "_ENABLE_INFO="
set _DBQ="
set "_PARMS.ORIGINAL=%*" && if defined _PARMS.ORIGINAL (
if not defined _PARMS.IDX (
echo Parameter Index^(es^) to extract eg.:
echo 1 2 5 9 11 39 400
set /p "_PARMS.IDX=>"
)
set "_PARMS.IDX=¡!_PARMS.IDX: =¡ ¡!¡"
set "_PARMS.IDX=!_PARMS.IDX:¡¡=!"
set "_PARMS.IDX=!_PARMS.IDX: =!"
call :_FN_PROC.STRING %*
%_ENABLE_INFO% goto :FINISH
goto :eof
) else (
echo No input parameters.
)
goto :eof
:_FN_PROC.STRING
set "_PARMS.PROCESS.STRING=%*"
:_FN_PROC.STRING.LOOP
set "_PARMS.PROCESS.STRING=!_PARMS.PROCESS.STRING:%_DBQ%=¡!"
set /a _PARMS.COUNT+=1
for /f "tokens=1* delims= " %%a in ("!_PARMS.PROCESS.STRING!") do (
set _PARMS.TMP.CHECK=%%a
set _PARMS.PROCESS.STRING=%%b
if "!_PARMS.TMP.CHECK!" NEQ "!_PARMS.TMP.CHECK:¡=!" (
for /f "tokens=1* delims=¡" %%c in ("%%a !_PARMS.PROCESS.STRING!") do (
set _PARMS.TMP.CHECK="%%c"
set _PARMS.PROCESS.STRING=%%d
)
)
)
if "!_PARMS.IDX:¡%_PARMS.COUNT%¡=!" EQU "!_PARMS.IDX!" (
set _PARMS.REMAINING=!_PARMS.REMAINING! !_PARMS.TMP.CHECK!
set _PARMS.IDX=!_PARMS.IDX!{%_PARMS.COUNT%}
) else (
set _PARMS.EXTRACTED=!_PARMS.EXTRACTED! !_PARMS.TMP.CHECK!
set _PARMS.IDX=!_PARMS.IDX:¡%_PARMS.COUNT%¡=!
set _PARMS.IDX=!_PARMS.IDX![%_PARMS.COUNT%]
)
if "!_PARMS.PROCESS.STRING: =!"=="" (set _PARMS.PROCESS.STRING=)
if defined _PARMS.PROCESS.STRING (goto :_FN_PROC.STRING.LOOP)
set _DBQ=
set _PARMS.TMP.CHECK=
if defined _PARMS.REMAINING (set _PARMS.REMAINING=!_PARMS.REMAINING:~1!)
if defined _PARMS.EXTRACTED (set _PARMS.EXTRACTED=!_PARMS.EXTRACTED:~1!)
goto :eof
:FINISH
echo.
echo _PARMS.IDX ^:
echo ¡^=¡ no Parameter Index was specified for extraction.
echo ¡n¡ nth Parameter was not processed (Index larger than Parameters Count).
echo [n] nth Parameter was Extracted.
echo {n} nth Parameter was Ignored (Remaining).
echo.
set _
goto :eof
call other.bat
使用给定的参数:“查询?而且,cls
在最终解决方案中也不需要