Solved

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

Posted on 2004-04-30
5
750 Views
Last Modified: 2010-05-18
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
Comment
Question by:LeTay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 10957758
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
 

Author Comment

by:LeTay
ID: 10957799
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
 

Author Comment

by:LeTay
ID: 10957814
.../...
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
 
LVL 67

Accepted Solution

by:
sirbounty earned 125 total points
ID: 10958133
Looks like you've got the general idea...
Just need to place a
 if [%1]=[] goto end
in there...
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10958326
I guess this is what SB is talking about:

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

GOTO GETFILE
:END

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question