batch parameters: everything after %1

Solution 1:

There is a shorter solution (one-liner) utilizing the tokenization capabilities of for loops:

:: all_but_first.bat
echo all: %*
for /f "tokens=1,* delims= " %%a in ("%*") do set ALL_BUT_FIRST=%%b
echo all but first: %ALL_BUT_FIRST%

output:

> all_but_first.bat foo bar baz
all: foo bar baz
all but first: bar baz

Footnote: Yes, this solution has issues. Same as pretty much anything written with batch files. It's 2021. Use Powershell or literally any other actual scripting language.

Solution 2:

I am not sure if there is a direct command but you can always use a simple loop and shift to get the result in a variable. Something like:

@echo off
set RESTVAR=
shift
:loop1
if "%1"=="" goto after_loop
set RESTVAR=%RESTVAR% %1
shift
goto loop1

:after_loop
echo %RESTVAR%

Let me know if it helps!

Solution 3:

The following will work for args with ", =, ' '. Based on Dmitry Sokolov answer. Fixed issue when second arg is the same as first arg.

@echo off
echo %*
set _tail=%*
call set _tail=%%_tail:*%1=%%
echo %_tail%