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
If there are more than 9 arguments, then tenth or onwards arguments can't be assigned as $10 or $11. You have to either process or save the $1 parameter, then with the help of shift command drop parameter 1 and move all other arguments down by one. It will make $10 as $9, $9 as $8 and so on.
There is no practical limit to the number of parameters you can pass to a batch file, but you can only address parameter 0 (%0 - The batch file name) through parameter 9 (%9).
Or may be you write programs in Java and for each operating system you have a script to set up an environment (sh-script or cmd-script). If you need to do basically the same in Windows and in Linux, you can write only one script, that will work in both operating systems.
It can be solved with reading from a temporary file a remarked version of the parameter. @echo off SETLOCAL DisableDelayedExpansion SETLOCAL for %%a in (1) do ( set "prompt=" echo on for %%b in (1) do rem * #%1# @echo off ) > param. txt ENDLOCAL for /F "delims=" %%L in (param.
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}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With