0

So i have a problem when i try to call a variable thats inside another variable! It will connect to a server to get a file with all users My Code is:

echo Please Login
set /p name=Username: 
set /p pass=Password: 
if exist users.txt del /f /q users.txt
wget server/users.txt // downloading file from Server
ren users.txt users.bat
call users.bat
del /f /q users.bat
if %%name%% equ %pass% goto login

So the %%name%% means that i need the variable thats inside name, so say "user". Now i need the variable inside "user"! And thats my problem i dont know how to call for that.

The file users.txt contains:

set name=pass
set name=pass
...

Where "name" is the players name and "pass" his password, So like:

set Blaze=1234
set test=5678

And now my file would call that to proceed.

Edit*
!%name%! solved my Problem! Thanks for your help guys!

BlazeLP
  • 135
  • 1
  • 8
  • Are you saying you are trying to do double expansion? If so, then you need to use delayed expansion like this. `if !%name%! equ %pass% goto login` – Squashman Nov 16 '16 at 19:45
  • I tried that. So when name=Blaze, then "!%name%!" would output "!Blaze!" – BlazeLP Nov 16 '16 at 20:10
  • Hello BlazeLP, I wouldn't download a file from a server and execute it without inspecting the commands in that file. You can parse the content of a file with `for /f` See `Help for` –  Nov 16 '16 at 20:47
  • Did you enable delayed expansion? http://ss64.com/nt/setlocal.html – Squashman Nov 16 '16 at 20:54
  • 2
    I suggest you to read [this answer](http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) about "arrays". The _concept_ involved is exactly the same... – Aacini Nov 16 '16 at 23:05

1 Answers1

0

For brevity I am just showing what you need to do. So that you can see that it works. The name variable resolves to Blaze and then when the line executes the variable Blaze resolves to 1234.

@echo off
setlocal enabledelayedexpansion
set "name=Blaze"
set "Blaze=1234"
set "pass=1234"
if "!%name%!"=="%pass%" echo Password Accepted
pause
Squashman
  • 13,649
  • 5
  • 27
  • 36