- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How does one set a variable variable?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
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
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- 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
тАО01-20-2003 04:12 PM
тАО01-20-2003 04:12 PM
For example:
MAIN=Sad
DEP=$MAIN" times"
echo $DEP would return "Sad times"
But what I'm looking for is if I were to next enter:
MAIN=Happy
echo $DEP would now return "Happy times"
I realize the above code won't give me what I want, but can something to this effect be accomplished? Any ideas?
Thanks,
Seth
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-20-2003 04:26 PM
тАО01-20-2003 04:26 PM
Re: How does one set a variable variable?
In a script, something like this:
#!/usr/bin/sh
MAIN="Sad"
OTHER=" times"
DEP=${MAIN}${OTHER}
echo ${DEP}
MAIN="Happy"
DEP=${MAIN}${OTHER}
echo ${DEP}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-20-2003 04:41 PM
тАО01-20-2003 04:41 PM
Re: How does one set a variable variable?
It is very simple to do this.
You just have to specify the parameter every time you want a value out of it. Only care you have to take is that you don't re-specify the variable value till you have got the result of the first one.
The earlier post explains it nicely.
-Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-20-2003 04:56 PM
тАО01-20-2003 04:56 PM
Re: How does one set a variable variable?
like
MAIN=Sad
TIM=times
then
echo $MAIN $TIM (will give Sad times)
and then
MAIN=happy
and echo $MAIN $TIM
would return happy times
Just give a try
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-20-2003 05:16 PM
тАО01-20-2003 05:16 PM
Re: How does one set a variable variable?
Does this make sense?
Thanks for the replies so far!
Seth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-20-2003 05:46 PM
тАО01-20-2003 05:46 PM
Re: How does one set a variable variable?
If you can, I don't know how to do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-20-2003 08:48 PM
тАО01-20-2003 08:48 PM
Re: How does one set a variable variable?
Since you are treating DEP as a vraible too you would need to reset the same in case you need to change $MAIN , the other was would be to use a shell scirpt to attaint eh same which can have if with 2 conditons.In the shell it wont be possible as the youy are dealing with two variables , and to set that you would need 2 statements not one.
Manoj Srivastava
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-21-2003 02:36 AM
тАО01-21-2003 02:36 AM
SolutionSet DEP to a string that includes the name of the variable.
$ DEP="\$MAIN times"
This effectively defers evaluation of $MAIN.
$ echo $DEP
$MAIN times
MAIN=Sad
$ eval echo $DEP
Sad times
$ MAIN=Happy
$ eval echo $DEP
Happy times
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-21-2003 03:42 AM
тАО01-21-2003 03:42 AM
Re: How does one set a variable variable?
Another example using awk:
export BOX1=yellow
export BOX2=lightgreen
export BOX3="#0080FF"
awk '{ color=ENVIRON[$1]
print "" $1 ""} ' <
BOX2
BOX3
END
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-21-2003 08:01 AM
тАО01-21-2003 08:01 AM
Re: How does one set a variable variable?
Thanks to you as well, Carlos. Nice example, but not quite what I was looking for.
And thanks to everyone else that took the time to reply.
Regards,
Seth