HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- nested variables (or dynamic variables)
Operating System - HP-UX
1826428
Members
3440
Online
109692
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2002 09:58 AM
05-28-2002 09:58 AM
How do we create a dynamic variable on korn shell ?. Or to put it in other words how do we reference a variable using values from other variables ?
For example, I want to refer the variable $XY using value of $a (X) and a constant value Y.
a=X
XY=test
abc=${${X}Y}} # This did not work...
any suggestions ?
- Vi
When going gets tough, upgrade. © Murphy.
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2002 10:00 AM
05-28-2002 10:00 AM
Re: nested variables (or dynamic variables)
sorry the script should be..
abc=${${a}Y}
I get an error 'bad substitution'...
abc=${${a}Y}
I get an error 'bad substitution'...
When going gets tough, upgrade. © Murphy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2002 10:43 AM
05-28-2002 10:43 AM
Re: nested variables (or dynamic variables)
I'm sure there's a better way to do it, but how about this:
#!/bin/sh
a=X
XY=test
abc=$(eval echo \$${a}Y)
echo $a:$XY:$abc
-Santosh
#!/bin/sh
a=X
XY=test
abc=$(eval echo \$${a}Y)
echo $a:$XY:$abc
-Santosh
Life is what's happening while you're busy making other plans
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2002 12:34 PM
05-28-2002 12:34 PM
Solution
eval is the way to go - it tells the shell to parse the line again.
a=X
XY=test
eval abc=\${${a}Y}
print $abc
test
This works as follows:
on the first pass the shell does parameter substitution of ${a} and ends up with
eval abc=${XY}
eval forces a second parameter substitution and you end up with
abc=test
Regards,
John
a=X
XY=test
eval abc=\${${a}Y}
print $abc
test
This works as follows:
on the first pass the shell does parameter substitution of ${a} and ends up with
eval abc=${XY}
eval forces a second parameter substitution and you end up with
abc=test
Regards,
John
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP