0
1.
@echo off
set "a=verA"
set "b=verB"
:a
echo %a1% & ^| & %b1%
echo %a2% & ^| & %b2%
pause 

2.
@echo off
set "1=hor1"
set "2=hor2"
:a
echo %a1% & ^| & %b1%
echo %a2% & ^| & %b2%
pause 

How to make variables change by any letter of their name?

So I would like to make the output look like this:

1.
verA | verB
verA | verB

2.
hor1 | hor1
hor2 | hor2
  • `echo %a% ^| %b%`. You didn't define `%a1%`, `%b1%`, etc. – Stephan Mar 04 '23 at 12:14
  • yes, because i don't know how to set all of variables that contain specific letter to something else – PringlesChips Mar 04 '23 at 12:27
  • `for /L %%i in (1,1,5) do (set "a%%i=verA" & set "b%%i=verB")` ? – Stephan Mar 04 '23 at 12:31
  • thanks, ill check that soon :) – PringlesChips Mar 04 '23 at 12:31
  • 3
    Also, you can;t set variables that begin with numerics. Well technically you can, but `%2` is interpreted as "the second parameter provided" for instance. It *is* possible to access a variable that starts numeric, but it's really not for beginners. – Magoo Mar 04 '23 at 14:52
  • **1.** You must first _define_ the variables. _"set all of variables"_ if there are not any variable have no sense. **2.** To set all variables that start with `a` to something else: `for /F "delims==" %%v in ('set a 2^>nul') do set "%%v=something else"` **3.** I suggest you to review [this answer](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) – Aacini Mar 04 '23 at 16:31

0 Answers0