How to shift arguments in batch files when there a

2019-08-06 08:06发布

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条回答
疯言疯语
2楼-- · 2019-08-06 08:27

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]
查看更多
登录 后发表回答