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
cmd
add a comment |
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
cmd
add a comment |
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
cmd
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
cmd
edited Nov 9 at 18:58
asked Nov 9 at 18:40
lit
5,34433050
5,34433050
add a comment |
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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