Documentation SHIFT command

#1
The first sentence of HELP -> SHIFT is:

"Purpose: Allows the use of more than 512 parameters in a batch file, or iterating through its parameters. This command can be used only in batch files."

In V05 the number was 256, since V06 the number is 512. In V08 and earlier versions the number matched the number of parameters directly accessible as %n. However, since V09 one can access up to 4096 parameters as %n. Shouldn't the number be updated?
 

samintz

Scott Mintz
May 20, 2008
1,264
11
Solon, OH, USA
#6
It depends on how you parse your command line arguments I suppose. You can loop until the %1 value is empty and SHIFT each time through the loop to get the next %1, or iterate over the count of arguments.
Code:
do until %1.=. 
    switch %1
    case A .OR. B
      echo %1
    caseall
      shift
    default
       echo usage: blah blah blah...
       quit
    endswitch
enddo
 
vs.
 
do i=1 to %#
   switch %[%i]
    case A .OR. B
      echo %[%i]
    default
       echo usage: blah blah blah...
       quit
    endswitch
enddo
-Scott
 
#7
Does SHIFT have any use other than CMD compatibility?
Yes - if you do not want to use %[%n] everywhere instead of %1, and there may be multiple parameters requiring identical processing.
It depends on how you parse your command line arguments I suppose. You can loop until the %1 value is empty and SHIFT each time through the loop to get the next %1, or iterate over the count of arguments.
When my batch program is designed to perform identical processing on multiple parameters, I found the structure below the simplest:

do while %# GT 0
REM process current %1
shift
enddo

This works without evaluating each parameter just for loop control, and even if an intermediate one is an empty string (which your version, Scott, would not handle).

Of course there are more elegant methods in other programming languages, but this is TCC, which has some archaic limitations.