yelo3
yelo3

Reputation: 5943

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!

Upvotes: 2

Views: 234

Answers (1)

jeb
jeb

Reputation: 82297

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 "=".

Upvotes: 1

Related Questions