• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 762
  • Last Modified:

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
0
LeTay
Asked:
LeTay
  • 2
  • 2
1 Solution
 
sirbountyCommented:
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.
<<
0
 
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 ?
0
 
LeTayAuthor Commented:
.../...
In fact how to I loop correctly ?
I suppose I write something like

set P=
.../...
:loop
set P=%P% %1
shift
goto loop
:end

But how to stop the loop ?
0
 
sirbountyCommented:
Looks like you've got the general idea...
Just need to place a
 if [%1]=[] goto end
in there...
0
 
ankuratvbCommented:
I guess this is what SB is talking about:

@ECHO OFF
:GETFILE
SHIFT
IF "%1"=="" GOTO END

GOTO GETFILE
:END

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now