- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Dynamically Change Environment 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
Forums
Discussions
Discussions
Discussions
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
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
12-19-2006 03:00 AM
12-19-2006 03:00 AM
In the Korn Shell, is there a method to dynamically change an environment variable based on another variable's changing?
I'm trying to use this:
BUD=/oravol/u3/dbbackup_${ORACLE_SID}/backups
export BUD
Where BUD would change values if ORACLE_SID changed. i.e. BUD needs to be re-evaluated each time it is referenced.
The single quotes make this happen for the PS1 environment variable:
PS1='${MYHOST} ${PWD} $ '
export PS1
I suspect that is a special case.
Any ideas?
TIA,
Tom
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2006 03:12 AM
12-19-2006 03:12 AM
Re: Dynamically Change Environment Variable
BUD=/oravol/u3/dbbackup_$ORACLE_SID/backups
No parens.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2006 04:26 AM
12-19-2006 04:26 AM
SolutionYou can do something like the following. I'll use the shell's SECONDS variable in this example:
# BUD='echo /oravol/u3/dbbackup_${SECONDS}/backups'
# eval ${BUD}
Those are single quotes in the variable assignent. Every time the 'eval' is executed, the current number of seconds (since the shell began executing) is displayed.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2006 05:01 AM
12-19-2006 05:01 AM
Re: Dynamically Change Environment Variable
Thanks. But that's what I had been trying and it didn't work.
James,
Thanks, that works. The "eval" could be a little cumbersome for our developers. I'm going to leave the Bunny off for a while to see if I can get any other suggestions.
Thanks again,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2006 05:21 AM
12-19-2006 05:21 AM
Re: Dynamically Change Environment Variable
To be clear, it is best to get in the habit of using curly braces when doing parameter substitution!
Consider:
# VAR=tom
# echo $VAR_was_here
sh: VAR_was_here: Parameter not set.
Now:
# VAR=tom
# echo ${VAR}_was_here
tom_was_here
As noted in the manpages for 'sh-posix', "Braces are required when parameter is followed by a letter, digit, or underscore that should not be interpreted as part of its name or when a named parameter is subscripted."
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2006 11:04 AM
12-19-2006 11:04 AM
Re: Dynamically Change Environment Variable
Thanks.
Yea, I almost always use the curley braces. I find myself forgetting occaisionally, but I've been doing that for 10 - 15 years.
Thanks again,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2006 12:34 PM
12-19-2006 12:34 PM
Re: Dynamically Change Environment Variable
My pointer regarding the use of curly braces was based upon the fact that you gave apparent credence to dropping them as a potential solution to your original query. The use of curly braces in parameter substitution is a very valuable habit to develop, in my opinion.
Regards!
...JRF...