I'm trying to display up to 9 parameters across the screen, and then display one fewer on each following line, until there are none left.
I tried this:
@echo off
echo %*
shift
echo %*
shift
echo %*
Actual Result:
a b c d e f
a b c d e f
Expected Result:
A B C D E F
B C D E F
C D E F
D E F
E F
F
Any help?
Thanks.
The shift command changes the values of the batch parameters %0 through %9 by copying each parameter into the previous one—the value of %1 is copied to %0, the value of %2 is copied to %1, and so on. This is useful for writing a batch file that performs the same operation on any number of parameters.
Pressing "y" would use the goto command and go back to start and rerun the batch file. Pressing any other key would exit the batch file.
[ == ] (Double Equals) The "IF" command uses this to test if two strings are equal: IF "%1" == "" GOTO HELP. means that if the first parameter on the command line after the batch file name is equal to nothing, that is, if a first parameter is not given, the batch file is to go to the HELP label.
When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.
SHIFT
is worthwhile if you want to get the value of %1
, %2
, etc. It doesn't affect %*
. This script gives you the output you expect.
@echo off
setlocal enabledelayedexpansion
set args=0
for %%I in (%*) do set /a "args+=1"
for /l %%I in (1,1,%args%) do (
set /a idx=0
for %%a in (%*) do (
set /a "idx+=1"
if !idx! geq %%I set /p "=%%a "<NUL
)
echo;
)
Output:
C:\Users\me\Desktop>test a b c d e f
a b c d e f
b c d e f
c d e f
d e f
e f
f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With