Batch file variables, need more than nine...

I’m trying to modify a batch file that we have here at work to perform additional functions. As it was, the batch file was taking nine parameters, labeled %1, %2, %3, etc…

Now, with the additional modifications, I need to pass in one more variable. However, %10 does not work.

I am aware of the SHIFT command. However, that is not usable in this instance. The %1 variable (the database server) is being used all over the script down to the last line. If I use SHIFT, then I will lose the %1 variable. In addition, I can’t re-arrange the existing variables either. We have several other batch files which run other functions and the format is to use the DB server as the %1 variable. I really don’t want to break that convention.

Does anyone have any suggestions?

Thanking you in advance,

Zev Steinhardt

It’s been ages since I used batch files, but aren’t there other variables - (syntax %%varname maybe possibly) you can use? Would something like %%server=%1 and then shift work?

You need to save the variables you need as other variables before the shift, a quick test shows that this …


@echo off
set db=%1
shift
echo %db% %1 %2 %3 %4 %5 %6 %7 %8 %9

Correctly stores the value of %1 in %db% which allows you to use it later and access ten parameters.

Hope that helps, I tried that on XP but as I recall it should work on most DOS systems.

SD

That worked. :slight_smile:

Thanks everyone.

Zev Steinhardt

Unless you’ll need the variable again, it is a good idea to begin the program with “setlocal” to make sure any variables you create do not propogate outside of the program. You do not need to use “endlocal” at the very end of a batch file (it is implicit when the batch file terminates) but you might need it if you plan to stop the use of those variables sooner.

I didn’t mean “propogate out of the program” as much as I meant “propogate outside of the block they are needed in.” If they are needed throughout the entire batch file, then “setlocal” isn’t necessary. Hope that clears things up.