Monday, January 3, 2011

Getting More then 9 parameters in a batch file

While calling a batch file using parameters we can use the parameters as %1,%2,etc.. But the 10th parameters can not be called as %10. Instead we should shift the parameters using SHIFT command and move the parameter one left. By this we can use the parameter 10 as %9

You can test it by using the below batch file by passing 10 parameters
c:\>kaarthik.bat a b c d e f g h i j
REM kaarthik.bat - file to test parameters
echo off
echo Program to test parameters
echo Parameter 1 : %1
echo Parameter 2 : %2
echo Parameter 3 : %3
echo Parameter 4 : %4
echo Parameter 5 : %5
echo Parameter 6 : %6
echo Parameter 7 : %7
echo Parameter 8 : %8
echo Parameter 9 : %9
echo Parameter 10 : %10
SHIFT
echo Parameter 10 : %9