batch: multiple FOR parameter taken from command arguments
this is what I'm trying to do
find.bat:开发者_运维知识库
@echo off
SET for_argument=%1
SET other_argument2=%2
SET other_argument3=%3
FOR %%A IN (%for_argument%) DO (
echo %%A
rem do other stuff
)
What I want to do is call
find.bat "1 2 3 4" arg2 arg3
and I want that FOR
to be executed with 1 2 3 4 as separated arguments, so that the output is
1
2
3
4
But unfortunately with this code the output is
"1 2 3 4"
Can you help me? Thanks!
SET "for_argument=%~1"
So you get in the for argument a b c d, but without the quotes, this is important for the FOR loop. A quoted string like "a b c d" is handled as one token, but a b c d is split into four tokens, allowed delims are space "," ";" or "=".
精彩评论