How to? A seemingly-stupid question related to the "Shift" command.

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
My goal is simple: If a certain parameter occurs I want to delete if from the list of parameters.

I think showing a complete transcript is the best route to go here:

Code:
   Thu  Jan 19, 2012   4:52:28p

ISO8601 plugin v1.1.1 loaded.
SafeChars plugin v1.5.7 loaded.
Sift v0.55.0 loaded.

TCC  12.11.76   Windows 7 [Version 6.1.7601]
Copyright 2011  Rex Conn & JP Software Inc.  All Rights Reserved
Registered to Daniel Mathews

[Z:\]Type TestShift.btm
@Echo Off
SetLocal
Set I=1
Do While %I LE %#
   Set Arg=%[%I]
   Iff "%@Left[2,%Arg]" == "/Z" Then
      @Echo On
      Shift -%I
      @Echo Off
   EndIff
   @Echo I: %I   %@Format[-3.3,%[%I] ]  %%$: %$
   Set /A I+=1
EndDo
EndLocal
Quit 0

[Z:\]TestShift a b c /z e f g
I: 1   a    %$: a b c /z e f g
I: 2   b    %$: a b c /z e f g
I: 3   c    %$: a b c /z e f g
Shift -4
I: 4   /z   %$: a b c /z e f g
I: 5   e    %$: a b c /z e f g
I: 6   f    %$: a b c /z e f g
I: 7   g    %$: a b c /z e f g

Simply put, that did not work at all (in fact, it seems to have done absolutely nothing), so below is a reasonable second try (although I expected the code above to work; not really so for the following code in which I simply deleted the minus sign in front of the "%I" on the "Shift" command):

Code:
[Z:\]type TestShift.btm
@Echo Off
SetLocal
Set I=1
Do While %I LE %#
   Set Arg=%[%I]
   Iff "%@Left[2,%Arg]" == "/Z" Then
      @Echo On
      Shift %I
      @Echo Off
   EndIff
   @Echo I: %I   %@Format[-3.3,%[%I] ]  %%$: %$
   Set /A I+=1
EndDo
EndLocal
Quit 0

[Z:\]TestShift a b c /z e f g
I: 1   a    %$: a b c /z e f g
I: 2   b    %$: a b c /z e f g
I: 3   c    %$: a b c /z e f g
Shift 4
I: 4        %$: e f g

So I was, in fact, correct in that expectation.

Simply put: What don't I understand? What am I doing wrong?

- Dan
 

samintz

Scott Mintz
May 20, 2008
1,204
11
Solon, OH, USA
#2
Dan,

I assume the goal is to turn a command line of "a b c /z e f g" into "a b c e f g".

You should use SHIFT /n.

I modified your first script and replaced the minus sign with a slash. I get this output:

Code:
foo a b c /z e f g
I: 1   a    %$: a b c /z e f g
I: 2   b    %$: a b c /z e f g
I: 3   c    %$: a b c /z e f g
Shift /4
I: 4   e    %$: a b c e f g
I: 5   f    %$: a b c e f g
I: 6   g    %$: a b c e f g
 
#3
Thank you, Scott. I just found the problem myself (both bad eyesight and the fact that the "help" command somewhat strangely started "misbehaving" so badly - it totally and completely "hung" every TCC session in which I entered it - "non-elevated" or elevated, and the Task Manager was totally unable to "kill" ("Access Denied") any of these "hung" TCC sessions). I actually had to reboot this machine to "cure" the problem - and even the "reboot" process seemed to have a "hard time" "killing" these "hung" TCC sessions - I got a series of "complaints" of some kind I really didn't fully understand, although it ultimately succeeded - which takes at least 20 minutes) and I was going to come here and delete this posting had nobody responded to it yet. Sorry!

- Dan