Computing.Net > Forums > Programming > Batch File - nested variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File - nested variables

Reply to Message Icon

Name: dude04
Date: August 28, 2008 at 19:14:50 Pacific
OS: XP
CPU/Ram: Intel 4GB
Comment:

Here is the scenario

set a=Test
set /P input=Please Enter a letter:

If the user enters "a" how can I associate "a" variable with input variable

essentially I would like to do something like this:

echo %%input%% and would expect to get "Test" which is the value of "a" variable

Is this possible and how would I go about doing it.

Thank you



Sponsored Link
Ads by Google

Response Number 1
Name: tonysathre
Date: August 28, 2008 at 19:40:42 Pacific
Reply:

set a=Test
set /P input=Please Enter a letter:
set a=%input%

EDIT: I should have read more carefully. I don't think this is what you mean.


0

Response Number 2
Name: Mechanix2Go
Date: August 28, 2008 at 23:16:39 Pacific
Reply:

Good question. I think we'll have to wait for IVO on this one.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 3
Name: Razor2.3
Date: August 29, 2008 at 00:47:14 Pacific
Reply:

What, like:


SETLOCAL ENABLEDELAYEDEXPANSION
set a=Test
set /P input=Please Enter a letter:
SET input=!%input%!


0

Response Number 4
Name: Judago
Date: August 29, 2008 at 01:30:06 Pacific
Reply:

Try:


set a=test
set input=a
call echo %%input%%

As you can see you can use commands after the call as per normal e.g.

call set b=%%input%%

should set %b% to test.

[edit]

Another thing I forgot to mention is if you set layer=input you could do the following to echo test:


call call echo %%%layer%%%


0

Response Number 5
Name: dude04
Date: August 29, 2008 at 09:06:30 Pacific
Reply:

Thank you everyone

Razor's suggestion worked very well.
For some reason call did not work for me as per Judago's suggestion.
Thank you again all for your help.

dude04


0

Related Posts

See More



Response Number 6
Name: Judago
Date: August 29, 2008 at 17:02:38 Pacific
Reply:

For some reason call did not work for me as per Judago's suggestion.

Are you using setlocal enabledelayedexpansion?

Using call didn't seem to work for me either when I enabled it(learn something new every day). Using Razor2.3's suggestion of using !%input%! when setlocal enabledelayedexpansion is in force is the right one.

When not using delayedexpansion, call seems to work fine(at least for me).


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File - nested variables

Batch file nested FOR loops help www.computing.net/answers/programming/batch-file-nested-for-loops-help/15196.html

batch file environment variables www.computing.net/answers/programming/batch-file-environment-variables/16190.html

Batch file www.computing.net/answers/programming/batch-file/18005.html