LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-16-2016, 10:27 AM   #1
youtoo
LQ Newbie
 
Registered: May 2015
Posts: 3

Rep: Reputation: Disabled
Environment variable that dynamically changes when another variable is changed


Bash Shell

I have a number of DBs on a server. I want to store paths to log files in .bash_profile as follows:

/mydir/mylowerdir/mydb/MYDB/mylog


mydb and MYDB will change when I change the ORACLE_SID parameter in memory. We set the ORACLE_SID using an ORACLE utility. We don't want to update the Oracle provided utility to also set paths.

Is there a way to have a parameter set in .bash_profile change automatically?
 
Old 02-16-2016, 11:13 AM   #2
dr_agon
Member
 
Registered: Sep 2007
Location: Poland
Distribution: Ubuntu LTS
Posts: 101
Blog Entries: 12

Rep: Reputation: 26
You cannot use environment variable for this, because it will be evaluated once (in .bash_profile) and keep the value.
But you can write bash function and use it every time you need.

Something like this in .bash_profile:
Code:
log_dir() { echo "/mydir/mylowerdir/${DB_NAME}/mylog"; }
Then use like this:
Code:
$ ls $(log_dir)
The function gets evaluated every time it is invoked, so if DB_NAME changes you will get different results.
 
Old 02-16-2016, 12:00 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,530

Rep: Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897
ORACLE_SID is itself an environment variable, so why not just relate your path to it?
 
Old 02-16-2016, 01:01 PM   #4
youtoo
LQ Newbie
 
Registered: May 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Cause the ORACLE_SID changes every time I set it.

the path would be

/mypath/$ORACLE_SID/lower($ORACLE_SID)

or something like that.

When I log in, bash_profile runs, but I may have 10 DBs on a server and I could change it later.
 
Old 02-17-2016, 01:44 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,530

Rep: Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897
Most Oracle environments I have worked on require sourcing of the environment variables for each DB as the SID is not the only thing to change.
So for each DB we have a env file and prior to working on said DB we do the following:
Code:
. DB_env
This sets our environment as required and away we go

If you actually mean you are changing the actual SID value regularly, which is dangerous for several reasons, you may wish to write a script to do the change and update the associated
env file
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
keep environment variable manelameur Ubuntu 13 02-05-2010 11:01 PM
AWK a variable Ouptut to a new variable and using the new variable with the old one alertroshannow Linux - Newbie 4 02-16-2009 12:08 AM
changed the value of PATH variable shamiksaha Linux - Newbie 1 06-05-2008 03:41 PM
Getting value of an environment variable dynamically naren_0101bits Programming 3 10-30-2007 05:58 AM
environment variable gamor Linux - Newbie 4 04-30-2005 05:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration