[Question] Echoing Veriables in Veriable..

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

[Question] Echoing Veriables in Veriable..

#1 Post by Ranguna173 » 28 Mar 2012 10:10

Hello! I haven't been here for a while!!
I'm gonna start learning XNA.. But Batch will always be here in my heart :D

Anyway, I have been trying to echo a variable inside another variable like this:

Code: Select all

C:>set SRC=1

C:\>set SR%SRC%=12

C:\>echo %SR1%
12

C:\>echo %SR%SRC%%
%SR1%

C:\>wtf?!


See there, when I echo %SR1% the output is 12 but then if I echo %SR%SRC%% the output is %SR1% :shock: :?:

Help Please.
Thanks :)

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: [Question] Echoing Veriables in Veriable..

#2 Post by Ranguna173 » 28 Mar 2012 10:32

Anyone??

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: [Question] Echoing Veriables in Veriable..

#3 Post by foxidrive » 28 Mar 2012 10:33

Code: Select all

@echo off
set SRC=1
set SR%SRC%=12
echo %SR1%
call echo %%SR%SRC%%%
pause


It doesn't function from a cmd prompt.

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: [Question] Echoing Veriables in Veriable..

#4 Post by Ranguna173 » 28 Mar 2012 10:55

foxidrive wrote:

Code: Select all

@echo off
set SRC=1
set SR%SRC%=12
echo %SR1%
call echo %%SR%SRC%%%
pause


It doesn't function from a cmd prompt.


Thank You Very Much!!!
Oh, and it is %SR%SRC%% not %%SR%SRC%%, I think cmd processes empty spaces in variables
See It is like
1st Processes the variable-
%SR%SRC%%
2nd it reads the deepest variable-
%SR1%
3rd It reads the next variable (SR%SRC%=12 which is the same thing as SR1=12)-
12

Didn't thought about manualy calling the variable..

Thanks :D

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: [Question] Echoing Veriables in Veriable..

#5 Post by Ranguna173 » 28 Mar 2012 11:09

foxidrive wrote:

Code: Select all

@echo off
set SRC=1
set SR%SRC%=12
echo %SR1%
call echo %%SR%SRC%%%
pause


It doesn't function from a cmd prompt.


Wait it doesn't work again.. Tha' he**?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: [Question] Echoing Veriables in Veriable..

#6 Post by foxidrive » 28 Mar 2012 11:12

try copy/paste again. :)

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: [Question] Echoing Veriables in Veriable..

#7 Post by !k » 28 Mar 2012 11:14

foxidrive wrote:

Code: Select all

@echo off
set SRC=1
set SR%SRC%=12
echo %SR1%
call echo %%SR%SRC%%%
pause

or

Code: Select all

@echo off
setlocal enabledelayedexpansion
set SRC=1
set SR%SRC%=12
echo %SR1%
echo !SR%SRC%!
pause

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: [Question] Echoing Veriables in Veriable..

#8 Post by Ranguna173 » 28 Mar 2012 11:21

!k wrote:

Code: Select all

@echo off
setlocal enabledelayedexpansion
set SRC=1
set SR%SRC%=12
echo %SR1%
echo !SR%SRC%!
pause

Nop The out put is !SR1!
It should be 12.

foxidrive wrote:try copy/paste again. :)

Hehe.. Looks like it doesn't work..

I have to do this:

Code: Select all

C:>set SRC=1

C:\>set SR%SRC%=12

C:\>echo %SR1%
12

C:\>echo %SR%SRC%%
%SR1%

C:\>call echo %SR%SRC%%
%SR1%

C:\>set SR1=12

C:\>echo C:\>echo %SR%SRC%%
12

C:\>echo C:\>call echo %SR%SRC%%
12

C:\>weird..


Thanks for your time.
(!k long time no read! :lol: )

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: [Question] Echoing Veriables in Veriable..

#9 Post by foxidrive » 28 Mar 2012 11:27

It looks like you have the random behaviour generator bug in your cmd window. Reboot your PC.

Both these work.

@echo off
set SRC=1
set SR%SRC%=12
echo %SR1%
call echo %%SR%SRC%%%
pause

@echo off
setlocal enabledelayedexpansion
set SRC=1
set SR%SRC%=12
echo %SR1%
echo !SR%SRC%!
pause

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: [Question] Echoing Veriables in Veriable..

#10 Post by Ranguna173 » 28 Mar 2012 11:41

foxidrive wrote:It looks like you have the random behaviour generator bug in your cmd window. Reboot your PC.


Hmm.. Maybe My commands are to complex for CMD :lol: and it just starts messing with me.. :( :wink:
I'll try that.

Thanks!

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: [Question] Echoing Veriables in Veriable..

#11 Post by Ranguna173 » 28 Mar 2012 12:33

foxidrive wrote:It looks like you have the random behaviour generator bug in your cmd window. Reboot your PC.


Nop The output for your code is %%SR1%% and the output for !k's is !SR1! ...

Don't worry about it, I'll just code somthing else... :cry:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: [Question] Echoing Veriables in Veriable..

#12 Post by foxidrive » 28 Mar 2012 12:38

Are you running the batch files or working at the command line?

Post Reply