6

I need to pass more than 10 arguments to a single batch file (shell script) but after the 9th argument it will not work (it will take from beginning)

code sample

 echo Hello! This a sample batch file.
    echo %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15 %16
    pause



>mybatchdotbat a b c d e f g h i j  k l m n o p

can anyone give solution for this

mkj
  • 2,761
  • 5
  • 24
  • 28
smartechno
  • 470
  • 1
  • 5
  • 18
  • I suspect the problem is that `%10` is being read as `%1` `0`. In a Unix shell, you could use `${10}` to refer to the tenth argument, or `shift` to remove the first argument and decrement all subsequent arguments by 1 (useful in a loop). – fzzfzzfzz Mar 13 '15 at 04:43

2 Answers2

3

Basically, %10 is getting interpreted as %1 0.

To fix this, in either a batch file or a shell script, you can save the first argument in a variable, then use shift to decrement all remaining arguments by 1. When you call shift, %1 ($1 in a shell script) is now gone, the old %2 becomes %1, the old %3 becomes %2, etc. See this answer for more details.

In a shell script, you can also refer to the tenth argument using ${10}.

Community
  • 1
  • 1
fzzfzzfzz
  • 1,248
  • 1
  • 12
  • 22
2

you can get all parameters with %* and parse them with a for loop:

for %%i in (%*) do echo %%i

Note: your parameters may not contain certain characters ("Standard delimiters"), for example , or ; unless you quote them:

mybatch.bat first second "this is the third" "four, not five" five 6 7 8 9 ...
Stephan
  • 53,940
  • 10
  • 58
  • 91