Dynamically changing environment variable

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

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....

By example, this would evaluate the actual value of $ORACLE_SID

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"

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

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

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

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.