Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Ranguna173
- Posts: 104
- Joined: 28 Jul 2011 17:32
#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
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%
Help Please.
Thanks

-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#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
#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

-
Ranguna173
- Posts: 104
- Joined: 28 Jul 2011 17:32
#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**?
-
!k
- Expert
- Posts: 378
- Joined: 17 Oct 2009 08:30
- Location: Russia
#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
#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!

)
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#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
#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

and it just starts messing with me..
I'll try that.
Thanks!
-
Ranguna173
- Posts: 104
- Joined: 28 Jul 2011 17:32
#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...

-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#12
Post
by foxidrive » 28 Mar 2012 12:38
Are you running the batch files or working at the command line?