I know I can get first argument with %0, second with %1, and so on.. And I can also get all arguments with %*.
Can I get all arguments from the second arguments? For example, if I run
foo.bat bar1 bar2 bar3 bar4
How can I get only bar2 bar3 bar4
?
@ECHO OFF
SETLOCAL
SET allargs=%*
IF NOT DEFINED allargs echo no args provided&GOTO :EOF
SET arg1=%1
CALL SET someargs=%%allargs:*%1=%%
ECHO allargs %allargs%
ECHO arg1 %arg1%
ECHO someargs %someargs%
This will leave SOMEARGS
with at least one leading separator (if it is set)
With SHIFT
command. But with every shift you'll lose the first.
This will not change the %*
but you'll be able to get all argument ,but the first:
@echo off
shift
set "arg_line= "
:parse_args
if "%~1" NEQ "" (
arg_line=%argline% "%~1"
goto :parse_args
)
now you'll have all arguments but the first stored in %arg_line%
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