Documentation SHIFT command

May 20, 2008
3,515
4
Elkridge, MD, USA
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?
 
Jan 19, 2011
605
15
Norman, OK
Or the sentence rewritten to avoid the use of a number altogether.

Which will lead to the inevitable question... "How many parameters will SHIFT handle?"
 
Jan 19, 2011
605
15
Norman, OK
(Does SHIFT have any use other than CMD compatibility?)

I have no clue; I've never used it. I think the only time I ever used a SHIFT command was in a PERL script.
 

samintz

Scott Mintz
May 20, 2008
1,514
18
Solon, OH, USA
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
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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.
 
May 24, 2010
855
0
Northlake, Il
Just as an FYI, I use Steve's technique all the time. Yet another wonderful feature of TCC (although I suppose it "inherited" it from cmd.exe ;)) - Dan
 
Similar threads
Thread starter Title Forum Replies Date
R Documentation Help for SHIFT Command Support 4
M How to? A seemingly-stupid question related to the "Shift" command. Support 2
M A somewhat humorous minor-request related to "Shift" command... Support 4
M Can "append to clipboard when shift is held down" be disabled? Support 1
vefatica Can I alias @@Ctrl-Shift-Alt-u? Support 4
MikeBaas Understanding SHIFT Support 3
W Pressing shift+enter Support 1
A How to? Copy+Paste in TCMD tabs with Ctrl-Shift-Ins? Support 5
D Shift+Enter no longer acts like "Enter" in TCC 24 Support 2
Charles Dye Ctrl-Shift-Up doesn't update directory history Support 1
Peter Murschall IDE destroys Text on Ctrl-U/Ctrl-Shift-U Support 12
Charles Dye Control-Shift-X Support 3
cgunhouse Ctrl + Shift keys and Paste (drop down menu and V) Support 4
F How to? Stop hijacking control-shift-z Support 6
D WAD Alt-Left doesn't work, but Alt-Shift-Left does Support 1
vefatica Ctrl-T and Ctrl-Shift-T Support 6
P Disable global hotkey Ctrl+Shift+T Support 19
dcantor Fixed Ctrl+Shift+Insert repeats last character Support 3
vefatica v10 Shift-Tab doesn't complete backwards Support 2
Z CMDDebug - TCC unknown command Support 2
F Edit command Support 1
rconn News Take Command / TCC / CMDebug / TCC-RT 28.02.17 Support 0
old coot LEAVE appears to affect command-line arguments Support 11
J VDESKTOP command Support 3
old coot tee command cancels colors Support 33
Dmitry L. Kobyakov How to? How to remove the record of the old version of the Take Command? Support 9
D Can alias pass parameters to for command? Support 3
samintz How to? Search for %(command) in Help? Support 1
T VIEW only works from command line Support 14
rconn News Take Command / TCC / CMDebug / TCC-RT v28 Released Support 0
T Take Command 28: Lua reports version 5.4.0 (5.4.3 expected) [SOLVED] Support 1
Jay Sage WAD Possible Bug With OPTION Command With @FILE Support 5
rconn News Take Command / TCC / CMDebug / TCC-RT 27.01.24 uploaded Support 0
J Take command does not start on Windows 10 Support 3
vefatica `Back quotes` - command line vs. batch file Support 5
Jay Sage WAD Failure of Alias Command with /Z Option Support 14
Phileosophos Is there any way to open the Take Command options dialog from the command line? Support 8
Phileosophos Command-line Editing Shortkeys That Fail Support 6
fpefpe How to? free (internal) command Support 0
rconn News Take Command / TCC / CMDebug / TCC-RT 27.01.23 uploaded Support 0
T How to? retain command history across reboot? Support 6
rconn News Take Command / TCC / CMDebug / TCC-RT v27.01 Build 22 Uploaded Support 0
Jay Sage Bug With Flow Control and/or Command Grouping Support 2
GermanDirk How to? EVENTLOG Command with simple User Rights not functional Support 4
Jay Sage Take Command Is Too Fast! Support 4
Jay Sage Comparison of IF with Command Group and IFF Support 6
D Open Windows 10 Photos app from command line Support 11
rconn News Take Command / TCC / CMDebug / TCC-RT 27.0.21 uploaded Support 0
rconn News Take Command / TCC / CMDebug / TCC-RT 27.0.20 uploaded Support 0
U Can not get/start Take Command gui Support 1

Similar threads