0

How do I make multiple "linear" variables on one line?

@echo off
setlocal enableDelayedExpansion
...more stuff

set /p input=(Number):
...more
:somewhere
(some commands to set variables)
:loop
if %loopcounter%==%input% goto somewhere
set /a loopcounter=loopcounter+1
set display=!d%loopcounter%!
echo %display%
pause
goto loop

So I get:
var1
var2
var3
var(anything up to %number%)
But how do I make it:
var1 var2 var3 var(anything up to %number%)

echo %var1% %var2% %var3% might not work because the amount of variables can go up to anything

Is there a way to "add" new variables to a variable without resetting it?

HuskyHus
  • 1
  • 1
  • 1
    Possible duplicate of [Windows batch: echo without new line](http://stackoverflow.com/questions/7105433/windows-batch-echo-without-new-line) – Melebius Jan 09 '17 at 07:42

2 Answers2

4

You can use <nul set/p ="%display% " (<-- space after) for that.

After a totally correct request by @jeb I will add some explanation:

With < you can send data over the standard input. In this case this substitutes the usual typing and pressing enter of the user that would usually type here due to the /p switch.
Sending nul results in an empty input.
So the only thing displayed is the string displayed asking for the user input (usually) which in this case is your variable.

Source

Community
  • 1
  • 1
geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
4

You could concat the strings first in a new variable.

set "display="
for /L %%n in (1 1 %input%) do (
  set "display=!display! !var%%n!"
)
echo !display!
jeb
  • 78,592
  • 17
  • 171
  • 225
  • Awesome! EXACTLY what I needed. I just need to reverse the variables now – HuskyHus Jan 06 '17 at 22:19
  • @HuskyHus If this is "EXACTLY" what you needed be fair and mark this as accepted answer. (Although I assume that it is already to late and this Husky is long gone...) – geisterfurz007 Jul 10 '17 at 12:27