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
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.
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
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).
Summary: Line 13 is actuall on one line so shouldn't need the ()s. I tried them and they don't help, neither does putting a CALL in front of !THECALL! (I know, I know, bad var name). !THECALL! gets set to %0 a...
Summary: I am trying to set environment variables with batch files by getting user input, something like this: set /p input = "Type something here: " echo You typed %input%. if "%input%" == "stop" goto stop I ...
Summary: Firstly in batch files no variables can start with numbers so !1! is invalid, this is because of a conflict(%2var%) of parameters %1 %2 ... You can just use !var1! or %var1% but if the number your usi...