# Dynamically changing environment variable

**URL:** <https://community.unix.com/t/dynamically-changing-environment-variable/356681>\
**Category:** Shell Programming and Scripting\
**Created:** [November 10, 2015, 2:29pm UTC](https://community.unix.com/t/dynamically-changing-environment-variable/356681 "2015-11-10T14:29:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![guessingo](https://community.unix.com/letter_avatar/guessingo/32/5_5575768a8748004e209b776fc1b2916d.png) [@guessingo](https://community.unix.com/u/guessingo)\
**Post date:** [November 10, 2015, 2:29pm UTC](https://community.unix.com/t/dynamically-changing-environment-variable/356681/1 "2015-11-10T14:29:26Z")

</div>

Linux Redhat, BASH Shell.

I want to put this in my .bash\_profile

I have log files that go to directory paths based in part on other variables such as went DB Name is set in memory. So if the DB Name changes the path to the log file changes. How do I create an environment variable I put into .bash\_profile that will change dynamically when another parameter changes?

if I do this, it only checks for $ORACLE\_SID, the first time the .bash\_profile is run.  
ORACLE\_SID=mydb  
LOG\_DIRECTORY=/var/opt/$ORACLE\_SID/logfile.log

so  
echo $LOG\_DIRECTORY=/var/opt/mydb/logfile.log

If the SID changes, I need the $LOG\_DIRECTORY variable in memory to change also. I don't want to do it manually. I would like the parameter to change that is from the .bash\_profile

I need ORACLE\_SID, to change dynamically whle the $LOG\_DIRECTORY is in memory

---

<div class="post-metadata">

**Author:** ![cjcox](https://community.unix.com/user_avatar/community.unix.com/cjcox/32/1232_2.png) [@cjcox](https://community.unix.com/u/cjcox)\
**Post date:** [November 10, 2015, 2:47pm UTC](https://community.unix.com/t/dynamically-changing-environment-variable/356681/2 "2015-11-10T14:47:31Z")

</div>

Linux, like most \*ix doesn't pass the symlink data through something that can evaluate a variable expression.

I think OSX might support this though and I know that Apollo OS's did (and likely HP-UX still has some support for this). As a former Apollo user you could create a symlink with a variable as part of the link name. In fact, you could could point your entire /usr space to run off somebody else's machine by merely changing and environment variable. It was also how they allowed you to easily switch shell flavors.

It's not that Oracle didn't go totally brain dead on how they did things, it's just that they don't want to change to become more modern. Oracle "stuff" like this has been around since before most people on this forum were probably born.

Good question, but the problem isn't lack of features in the shell or OS, the problem is Oracle....

---

<div class="post-metadata">

**Author:** ![blackrageous](https://community.unix.com/user_avatar/community.unix.com/blackrageous/32/2911_2.png) [@blackrageous](https://community.unix.com/u/blackrageous)\
**Post date:** [November 10, 2015, 2:54pm UTC](https://community.unix.com/t/dynamically-changing-environment-variable/356681/3 "2015-11-10T14:54:42Z")

</div>

By example, this would evaluate the actual value of $ORACLE\_SID

```nohighlight
LOG_DIRECTORY="/var/opt/\$ORACLE_SID/logfile.log"

```

Note your comment: "I need ORACLE\_SID, to change dynamically whle the $LOG\_DIRECTORY is in memory" seems conceptually wrong or it is not clear what you mean"

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [November 10, 2015, 3:56pm UTC](https://community.unix.com/t/dynamically-changing-environment-variable/356681/4 "2015-11-10T15:56:18Z")

</div>

How do you change the ORACLE\_SID? With an alias? A script? A function? Put the path change into that script/function as well.

---

<div class="post-metadata">

**Author:** ![cjcox](https://community.unix.com/user_avatar/community.unix.com/cjcox/32/1232_2.png) [@cjcox](https://community.unix.com/u/cjcox)\
**Post date:** [November 10, 2015, 4:07pm UTC](https://community.unix.com/t/dynamically-changing-environment-variable/356681/5 "2015-11-10T16:07:32Z")

</div>

My guess is that ORACLE\_SID is changed merely by changing the value of the variable, but will wait for the OP to respond.

---

<div class="post-metadata">

**Author:** ![blackrageous](https://community.unix.com/user_avatar/community.unix.com/blackrageous/32/2911_2.png) [@blackrageous](https://community.unix.com/u/blackrageous)\
**Post date:** [November 10, 2015, 5:15pm UTC](https://community.unix.com/t/dynamically-changing-environment-variable/356681/6 "2015-11-10T17:15:48Z")

</div>

ORACLE\_SID is an environment var (site identifier) that corresponds to a particular environment.

I don't understand what you mean by dynamically changing it in memory. Generally the environment is set and you launch the environment.

Why do you want to change the SID, what is your use case?

Are you trying to get a running environment to access another environment (i.e. a shared memory segment)?

I will change my ORACLE\_SID or entire oracle environment normally when I want to access a different instance/environment that is already running. Many folks will define different oracle users that have distinct environments (hence different ORACLE\_SIDs).

Refer to this link:

[https://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11\_QUESTION\_ID:318216852435](https://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11%5C_QUESTION_ID:318216852435)

---

<div class="post-metadata">

**Author:** ![cjcox](https://community.unix.com/user_avatar/community.unix.com/cjcox/32/1232_2.png) [@cjcox](https://community.unix.com/u/cjcox)\
**Post date:** [November 10, 2015, 5:56pm UTC](https://community.unix.com/t/dynamically-changing-environment-variable/356681/7 "2015-11-10T17:56:56Z")

</div>

Love to hear from the OP.

However, as an Oracle user, I think the idea is switch SIDs without having to source in oraenv.

In other words, making switching SIDs easier.

Why switch SIDs? Maybe you have more than one instance? It's an ok use case thing.

If switching SIDs is just something done from inside of a script, I'd just set my ORACLE\_SID and source in oraenv.sh, done.... but there could still be a desire for something better than this.

Imagine if ORACLE\_SID could be a path. Then the SID could be the basename and the other ORACLE elements could be folders (or symlinks) off that ORACLE\_SID path if env vars aren't specified, etc... just an idea. And certainly not something I expect Oracle to do.
