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.
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?
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.