Search code examples
batch-filecmd

Using Batch file SHIFT command


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

Solution

  • Shift doesn't change the actual order, just the index/pointer into the arguments.

    Try this:

    @echo off
    echo %1
    shift 
    echo %1
    shift
    echo %1
    echo %*
    

    And you get this:

    a
    b
    c
    a b c d