1

I'm making a bat file which add/load/rename savegame slots, and I had problem with some variables, the first variable is savegame number, the second variable is the name of the savegame, here is the code I've tried:

@echo off
set savename2=FortySeven
set nb=2
echo %savename%nb%%
pause

The result I have got is nb%

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Omar Mejdi
  • 59
  • 5
  • 1
    Replace `echo %savename%nb%%` by `call echo %%savename%nb%%%`... – aschipfl Oct 19 '19 at 17:49
  • **-->** https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990 – Aacini Oct 23 '19 at 17:14

1 Answers1

2

Either enable delayed expansion:

@Echo Off
Set "savename2=FortySeven"
Set "nb=2"
SetLocal EnableDelayedExpansion
Echo !savename%nb%!
Pause
EndLocal

Or, use Call for that expansion:

@Echo Off
Set "savename2=FortySeven"
Set "nb=2"
Call Echo %%savename%nb%%%
Pause
Compo
  • 36,585
  • 5
  • 27
  • 39
  • What about the opposite? For example i have this: `set save=connor echo %save%` of course it will show `connor` but what if i want it to print `%save%` , is it possible? – Omar Mejdi Oct 30 '19 at 09:05
  • 1
    In most circumstances, you'd use `Echo %%save%%`. Please understand that the responders of your previous questions aren't contracted to you for any follow up questions. Also that follow up questions should be written and posted as new questions, with a referring link if required. – Compo Oct 30 '19 at 09:41
  • My apologizes sir, i am already new here, and i don't know the rules well, by the way, i want to thank u for ur answere and for your time. But as i've said, im newbie, so i ask u what should i do right now, to put everything in its place if necessairy – Omar Mejdi Oct 30 '19 at 09:56