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%
You need to use SHIFT
. It moves the apparent position of the parameters, then %*
will get all parameters from the position shifted to. You should get the first parameters before using SHIFT
.
More information on SHIFT
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.