concatenation of all parameters (%1 %2) in a .bat file

I know this is possible but don't remember how
I have a script.bat that can accept a lot of parms (more than 10)
I need inside the script to build a variable, says P which will contain all these parameters concatenated.
SO P=%1 %2 %3 ... will work but how to build it with more (undetermined number) than 9 parameters
Who is Participating?
sirbountyConnect With a Mentor Commented:
Looks like you've got the general idea...
Just need to place a
 if [%1]=[] goto end
in there...
You'll need to use SHIFT
Changes the position of replaceable parameters in a batch file.

SHIFT [/n]

If Command Extensions are enabled the SHIFT command supports
the /n switch which tells the command to start shifting at the
nth argument, where n may be between zero and eight.  For example:

    SHIFT /2

would shift %3 to %2, %4 to %3, etc. and leave %0 and %1 unaffected.
LeTayAuthor Commented:
I know that shift command, but practically how do I do ?
Assume sample.bat is the batch which need to set P to all argument passed
What is the cod in sample.bat to achieve this ?
LeTayAuthor Commented:
In fact how to I loop correctly ?
I suppose I write something like

set P=
set P=%P% %1
goto loop

But how to stop the loop ?
I guess this is what SB is talking about:

IF "%1"=="" GOTO END


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.