Tip: Batch files with over 9 parameters
· 2008-10-14 20:27 by Thijs Kroesbergen for Brokenwire.NET
This has been around for ages, but it saved a us lot of work today (once we figured this out)..
So when you are writing a batch file (.cmd file) to automate some stuff you might run in to the issue that you can only retrieve the command line parameters up to number 9, by using the %1 to %9 variables.
Example:
@echo off
SET ONE=%1
SET TWO=%2
SET THREE=%3
SET FOUR=%4
SET FIVE=%5
SET SIX=%6
SET SEVEN=%7
SET EIGHT=%8
SET NINE=%9
So what do you do when you need number ten and up? %10 and up don't exist! Solution: You use the "shift" command!
Every time you call SHIFT the parameters will move 1 position, so if you call it ten times...
SHIFT
SHIFT
SHIFT
SHIFT
SHIFT
SHIFT
SHIFT
SHIFT
SHIFT
then you can retrieve number 10 and up..
SET TEN=%1
SET ELEVEN=%2
SET TWELVE=%3
SET THIRTEEN=%4
SET FOURTEEN=%5
SET FIFTEEN=%6
SET SIXTEEN=%7
SET SEVENTEEN=%8
SET EIGHTEEN=%9
How about that! (Be honest, did you know this?)
Even after working with BAT files for many years, batch files still surprise me! Cool
— Leon Meijer 2008-10-15 11:34 #
Batch is so easy to learn yet so versatile when you become familiar with it
— 2012-09-23 22:01 #