Why is SHIFT not changing the values?











up vote
1
down vote

favorite












It appears that SHIFT is not working or I do not understand it. Here is the script I am trying to make work.



C:>type shiftit.bat
@echo off
echo all is %*
echo 0 is %0
echo 5 is %5
shift /5
echo shifted by 5
echo 0 is %0
echo 1 is %1
echo 2 is %2


However, I would have expected that after the shift, %1 would contain "5" or "6". It does not. It appears that the SHIFT /5 command had no effect. What am I missing?



12:57:25.78  C:srct
C:>cmd /E:ON
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

12:57:29.57 C:srct
C:>shiftit.bat 1 2 3 4 5 6 7 8 9
all is 1 2 3 4 5 6 7 8 9
0 is shiftit.bat
5 is 5
shifted by 5
0 is shiftit.bat
1 is 1
2 is 2









share|improve this question




























    up vote
    1
    down vote

    favorite












    It appears that SHIFT is not working or I do not understand it. Here is the script I am trying to make work.



    C:>type shiftit.bat
    @echo off
    echo all is %*
    echo 0 is %0
    echo 5 is %5
    shift /5
    echo shifted by 5
    echo 0 is %0
    echo 1 is %1
    echo 2 is %2


    However, I would have expected that after the shift, %1 would contain "5" or "6". It does not. It appears that the SHIFT /5 command had no effect. What am I missing?



    12:57:25.78  C:srct
    C:>cmd /E:ON
    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    12:57:29.57 C:srct
    C:>shiftit.bat 1 2 3 4 5 6 7 8 9
    all is 1 2 3 4 5 6 7 8 9
    0 is shiftit.bat
    5 is 5
    shifted by 5
    0 is shiftit.bat
    1 is 1
    2 is 2









    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      It appears that SHIFT is not working or I do not understand it. Here is the script I am trying to make work.



      C:>type shiftit.bat
      @echo off
      echo all is %*
      echo 0 is %0
      echo 5 is %5
      shift /5
      echo shifted by 5
      echo 0 is %0
      echo 1 is %1
      echo 2 is %2


      However, I would have expected that after the shift, %1 would contain "5" or "6". It does not. It appears that the SHIFT /5 command had no effect. What am I missing?



      12:57:25.78  C:srct
      C:>cmd /E:ON
      Microsoft Windows [Version 6.1.7601]
      Copyright (c) 2009 Microsoft Corporation. All rights reserved.

      12:57:29.57 C:srct
      C:>shiftit.bat 1 2 3 4 5 6 7 8 9
      all is 1 2 3 4 5 6 7 8 9
      0 is shiftit.bat
      5 is 5
      shifted by 5
      0 is shiftit.bat
      1 is 1
      2 is 2









      share|improve this question















      It appears that SHIFT is not working or I do not understand it. Here is the script I am trying to make work.



      C:>type shiftit.bat
      @echo off
      echo all is %*
      echo 0 is %0
      echo 5 is %5
      shift /5
      echo shifted by 5
      echo 0 is %0
      echo 1 is %1
      echo 2 is %2


      However, I would have expected that after the shift, %1 would contain "5" or "6". It does not. It appears that the SHIFT /5 command had no effect. What am I missing?



      12:57:25.78  C:srct
      C:>cmd /E:ON
      Microsoft Windows [Version 6.1.7601]
      Copyright (c) 2009 Microsoft Corporation. All rights reserved.

      12:57:29.57 C:srct
      C:>shiftit.bat 1 2 3 4 5 6 7 8 9
      all is 1 2 3 4 5 6 7 8 9
      0 is shiftit.bat
      5 is 5
      shifted by 5
      0 is shiftit.bat
      1 is 1
      2 is 2






      cmd






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 18:58

























      asked Nov 9 at 18:40









      lit

      5,34433050




      5,34433050
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You didn't understand right,
          shift /5 will remove the argument %5, so %6 becomes %5, %7 -> %6 etc.



          To remove %1 .. %5 you will have to shift 5 times.

          The allargs %* is unaffected by shifting.



          See changed batch



          :: shiftit.bat 1 2 3 4 5 6 7 8 9
          @echo off
          echo all is %*
          Echo %%1 IS %1
          Echo %%2 IS %2
          Echo %%3 IS %3
          Echo %%4 IS %4
          Echo %%5 IS %5
          Echo %%6 IS %6
          Echo %%7 IS %7
          Echo %%8 IS %8
          Echo %%9 IS %9
          shift /5
          echo shifted by 5

          echo all is %*
          Echo %%1 IS %1
          Echo %%2 IS %2
          Echo %%3 IS %3
          Echo %%4 IS %4
          Echo %%5 IS %5
          Echo %%6 IS %6
          Echo %%7 IS %7
          Echo %%8 IS %8
          Echo %%9 IS %9


          And sample output:



          > shiftit.bat 1 2 3 4 5 6 7 8 9
          all is 1 2 3 4 5 6 7 8 9
          %1 IS 1
          %2 IS 2
          %3 IS 3
          %4 IS 4
          %5 IS 5
          %6 IS 6
          %7 IS 7
          %8 IS 8
          %9 IS 9
          shifted by 5
          all is 1 2 3 4 5 6 7 8 9
          %1 IS 1
          %2 IS 2
          %3 IS 3
          %4 IS 4
          %5 IS 6
          %6 IS 7
          %7 IS 8
          %8 IS 9
          %9 IS





          share|improve this answer

















          • 1




            That is absolutely right. It is indeed often unexpected that %* does not change on using command SHIFT one or more times without or with argument number. SHIFT affects only numbered argument references, i.e. %1, %2, %3 without or with a modifier as written by LotPings, but not all arguments reference %*. That is clearly documented by Microsoft documentation on command SHIFT.
            – Mofi
            Nov 9 at 22:06











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231594%2fwhy-is-shift-not-changing-the-values%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          You didn't understand right,
          shift /5 will remove the argument %5, so %6 becomes %5, %7 -> %6 etc.



          To remove %1 .. %5 you will have to shift 5 times.

          The allargs %* is unaffected by shifting.



          See changed batch



          :: shiftit.bat 1 2 3 4 5 6 7 8 9
          @echo off
          echo all is %*
          Echo %%1 IS %1
          Echo %%2 IS %2
          Echo %%3 IS %3
          Echo %%4 IS %4
          Echo %%5 IS %5
          Echo %%6 IS %6
          Echo %%7 IS %7
          Echo %%8 IS %8
          Echo %%9 IS %9
          shift /5
          echo shifted by 5

          echo all is %*
          Echo %%1 IS %1
          Echo %%2 IS %2
          Echo %%3 IS %3
          Echo %%4 IS %4
          Echo %%5 IS %5
          Echo %%6 IS %6
          Echo %%7 IS %7
          Echo %%8 IS %8
          Echo %%9 IS %9


          And sample output:



          > shiftit.bat 1 2 3 4 5 6 7 8 9
          all is 1 2 3 4 5 6 7 8 9
          %1 IS 1
          %2 IS 2
          %3 IS 3
          %4 IS 4
          %5 IS 5
          %6 IS 6
          %7 IS 7
          %8 IS 8
          %9 IS 9
          shifted by 5
          all is 1 2 3 4 5 6 7 8 9
          %1 IS 1
          %2 IS 2
          %3 IS 3
          %4 IS 4
          %5 IS 6
          %6 IS 7
          %7 IS 8
          %8 IS 9
          %9 IS





          share|improve this answer

















          • 1




            That is absolutely right. It is indeed often unexpected that %* does not change on using command SHIFT one or more times without or with argument number. SHIFT affects only numbered argument references, i.e. %1, %2, %3 without or with a modifier as written by LotPings, but not all arguments reference %*. That is clearly documented by Microsoft documentation on command SHIFT.
            – Mofi
            Nov 9 at 22:06















          up vote
          1
          down vote



          accepted










          You didn't understand right,
          shift /5 will remove the argument %5, so %6 becomes %5, %7 -> %6 etc.



          To remove %1 .. %5 you will have to shift 5 times.

          The allargs %* is unaffected by shifting.



          See changed batch



          :: shiftit.bat 1 2 3 4 5 6 7 8 9
          @echo off
          echo all is %*
          Echo %%1 IS %1
          Echo %%2 IS %2
          Echo %%3 IS %3
          Echo %%4 IS %4
          Echo %%5 IS %5
          Echo %%6 IS %6
          Echo %%7 IS %7
          Echo %%8 IS %8
          Echo %%9 IS %9
          shift /5
          echo shifted by 5

          echo all is %*
          Echo %%1 IS %1
          Echo %%2 IS %2
          Echo %%3 IS %3
          Echo %%4 IS %4
          Echo %%5 IS %5
          Echo %%6 IS %6
          Echo %%7 IS %7
          Echo %%8 IS %8
          Echo %%9 IS %9


          And sample output:



          > shiftit.bat 1 2 3 4 5 6 7 8 9
          all is 1 2 3 4 5 6 7 8 9
          %1 IS 1
          %2 IS 2
          %3 IS 3
          %4 IS 4
          %5 IS 5
          %6 IS 6
          %7 IS 7
          %8 IS 8
          %9 IS 9
          shifted by 5
          all is 1 2 3 4 5 6 7 8 9
          %1 IS 1
          %2 IS 2
          %3 IS 3
          %4 IS 4
          %5 IS 6
          %6 IS 7
          %7 IS 8
          %8 IS 9
          %9 IS





          share|improve this answer

















          • 1




            That is absolutely right. It is indeed often unexpected that %* does not change on using command SHIFT one or more times without or with argument number. SHIFT affects only numbered argument references, i.e. %1, %2, %3 without or with a modifier as written by LotPings, but not all arguments reference %*. That is clearly documented by Microsoft documentation on command SHIFT.
            – Mofi
            Nov 9 at 22:06













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You didn't understand right,
          shift /5 will remove the argument %5, so %6 becomes %5, %7 -> %6 etc.



          To remove %1 .. %5 you will have to shift 5 times.

          The allargs %* is unaffected by shifting.



          See changed batch



          :: shiftit.bat 1 2 3 4 5 6 7 8 9
          @echo off
          echo all is %*
          Echo %%1 IS %1
          Echo %%2 IS %2
          Echo %%3 IS %3
          Echo %%4 IS %4
          Echo %%5 IS %5
          Echo %%6 IS %6
          Echo %%7 IS %7
          Echo %%8 IS %8
          Echo %%9 IS %9
          shift /5
          echo shifted by 5

          echo all is %*
          Echo %%1 IS %1
          Echo %%2 IS %2
          Echo %%3 IS %3
          Echo %%4 IS %4
          Echo %%5 IS %5
          Echo %%6 IS %6
          Echo %%7 IS %7
          Echo %%8 IS %8
          Echo %%9 IS %9


          And sample output:



          > shiftit.bat 1 2 3 4 5 6 7 8 9
          all is 1 2 3 4 5 6 7 8 9
          %1 IS 1
          %2 IS 2
          %3 IS 3
          %4 IS 4
          %5 IS 5
          %6 IS 6
          %7 IS 7
          %8 IS 8
          %9 IS 9
          shifted by 5
          all is 1 2 3 4 5 6 7 8 9
          %1 IS 1
          %2 IS 2
          %3 IS 3
          %4 IS 4
          %5 IS 6
          %6 IS 7
          %7 IS 8
          %8 IS 9
          %9 IS





          share|improve this answer












          You didn't understand right,
          shift /5 will remove the argument %5, so %6 becomes %5, %7 -> %6 etc.



          To remove %1 .. %5 you will have to shift 5 times.

          The allargs %* is unaffected by shifting.



          See changed batch



          :: shiftit.bat 1 2 3 4 5 6 7 8 9
          @echo off
          echo all is %*
          Echo %%1 IS %1
          Echo %%2 IS %2
          Echo %%3 IS %3
          Echo %%4 IS %4
          Echo %%5 IS %5
          Echo %%6 IS %6
          Echo %%7 IS %7
          Echo %%8 IS %8
          Echo %%9 IS %9
          shift /5
          echo shifted by 5

          echo all is %*
          Echo %%1 IS %1
          Echo %%2 IS %2
          Echo %%3 IS %3
          Echo %%4 IS %4
          Echo %%5 IS %5
          Echo %%6 IS %6
          Echo %%7 IS %7
          Echo %%8 IS %8
          Echo %%9 IS %9


          And sample output:



          > shiftit.bat 1 2 3 4 5 6 7 8 9
          all is 1 2 3 4 5 6 7 8 9
          %1 IS 1
          %2 IS 2
          %3 IS 3
          %4 IS 4
          %5 IS 5
          %6 IS 6
          %7 IS 7
          %8 IS 8
          %9 IS 9
          shifted by 5
          all is 1 2 3 4 5 6 7 8 9
          %1 IS 1
          %2 IS 2
          %3 IS 3
          %4 IS 4
          %5 IS 6
          %6 IS 7
          %7 IS 8
          %8 IS 9
          %9 IS






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 19:46









          LotPings

          16.1k61531




          16.1k61531








          • 1




            That is absolutely right. It is indeed often unexpected that %* does not change on using command SHIFT one or more times without or with argument number. SHIFT affects only numbered argument references, i.e. %1, %2, %3 without or with a modifier as written by LotPings, but not all arguments reference %*. That is clearly documented by Microsoft documentation on command SHIFT.
            – Mofi
            Nov 9 at 22:06














          • 1




            That is absolutely right. It is indeed often unexpected that %* does not change on using command SHIFT one or more times without or with argument number. SHIFT affects only numbered argument references, i.e. %1, %2, %3 without or with a modifier as written by LotPings, but not all arguments reference %*. That is clearly documented by Microsoft documentation on command SHIFT.
            – Mofi
            Nov 9 at 22:06








          1




          1




          That is absolutely right. It is indeed often unexpected that %* does not change on using command SHIFT one or more times without or with argument number. SHIFT affects only numbered argument references, i.e. %1, %2, %3 without or with a modifier as written by LotPings, but not all arguments reference %*. That is clearly documented by Microsoft documentation on command SHIFT.
          – Mofi
          Nov 9 at 22:06




          That is absolutely right. It is indeed often unexpected that %* does not change on using command SHIFT one or more times without or with argument number. SHIFT affects only numbered argument references, i.e. %1, %2, %3 without or with a modifier as written by LotPings, but not all arguments reference %*. That is clearly documented by Microsoft documentation on command SHIFT.
          – Mofi
          Nov 9 at 22:06


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231594%2fwhy-is-shift-not-changing-the-values%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Schultheiß

          Verwaltungsgliederung Dänemarks

          Liste der Kulturdenkmale in Wilsdruff