3

The well-know shift command can be used to shift positional parameters in batch file, BUT it does not affect the special variable %*.

The shift command has no effect on the %* batch parameter.

Is there an alternative for shifting ?

  • batch is torture. – v.oddou Mar 9 '18 at 9:56
0

Unfortunately, no, there is no built in syntax to do what you want. The best you can do is use a loop to build a variable containing the desired list of parameters. Each iteration adds %1 to the list and then shifts. The loop continues until there are no more parameters.

This will only work if the parameters do not contain any unquoted poison characters.

@echo off

shift /1
shift /1

set "remainingArgs="
:getRemainingArgs
if "%~1" neq "" (
  set ^"remainingArgs=%remainingArgs% %1"
  shift /1
  goto :getRemainingArgs
)
echo remainingArgs=%remainingArgs%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.