Computing.Net > Forums > Programming > Variables in Windows batch files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Variables in Windows batch files

Reply to Message Icon

Name: dskw
Date: July 8, 2005 at 20:11:53 Pacific
OS: XP Pro SP2
CPU/Ram: 1.8 GHz P4 / 768MB DDR
Comment:

How can I resolve a variable inside a variable? For instance:

@echo off
set abc=123
set no123=success
echo Should display success
echo %no%abc%%
pause

The above commands should display the string 'success'. However, it doesn't. What I would like to do is to resolve %no%abc%% to %no123% (since %abc%=123) then resolve %no123% to 'success'. Any solutions? Thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: July 9, 2005 at 13:37:41 Pacific
Reply:

You need to enable the "delayed expansion of variables" then you have to use the ! symbols for the external variable noXXX and % for the inner one abc (the index).

Your code would be as the following

@echo off
SetLocal EnableDelayedExpansion

set abc=123
set no123=success
echo Should display success
echo !no%abc%!

EndLocal
pause

I hope that solves your question.


0

Response Number 2
Name: dskw
Date: July 9, 2005 at 19:08:41 Pacific
Reply:

Thank you so much! With this solution, I can finally finish all my projects which I abandoned halfway :) Thanks again!


0
Reply to Message Icon

Related Posts

See More


database question question on ' not equal t...



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: Variables in Windows batch files

Text Input Box in a Batch File www.computing.net/answers/programming/text-input-box-in-a-batch-file/15016.html

Batch File to clean folders www.computing.net/answers/programming/batch-file-to-clean-folders/11862.html

Get a Folder size in a batch file www.computing.net/answers/programming/get-a-folder-size-in-a-batch-file/9587.html