How to shift arguments in batch files when there are more than 10 arguments

ぐ巨炮叔叔 提交于 2019-12-13 17:59:46

问题


I am learning how to write batch files for Windows 7 using the VBScript like native scripting language.

I suppose I am not using the Windows Scripting Host or the Power Shell. I am using the simple old style VBScript like syntax.

I don't understand how to shift arguments when there are more than 9 arguments (or 10 including the name of the batch file) passed to the batch file.

Could you please teach me that?

Let us assume that you called my batch file with the following arguments:

C:\>call my.bat "one" "two" "three" "four" 
    "five" "six" "seven" "eight" "nine" "ten" "eleven"

How would you access the arguments ten and eleven from within my.bat?


回答1:


this is the batch taken from ss64.com

@echo off
:start
if "%1"=="" (goto :exit)
:: Do whatever with token %1
Echo [%1] 
:: Shift %2 into %1 
SHIFT
goto :start

:exit
::pause

call that batch with more than 10 arguments, it will display all

    shift.bat 1 2 3 4 5 6 7 8 9 10 11
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
[10]
[11]


来源:https://stackoverflow.com/questions/21546606/how-to-shift-arguments-in-batch-files-when-there-are-more-than-10-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!