Trying to figure out how the environment variables are being set

I just started a new job and I've been tasked with cleaning up the files that set up all the environment variables. The system works as is. What happens is:

  1. You log in to the server.
  2. You call a file that sets a bunch of environment variables and that displays a list of all the databases you can connect to.
  3. You select the database you want to connect to by calling a file that contains all the environment variables for that specific database (i.e. . filename).

This is all straight forward for some databases, but with others the file name starts with a period. Even though it starts with a period, executing the file with the . filename syntax seems to work fine.

With one database, there is no file under the home directory named after the database, and yet when you execute . filename for that database, you connect just fine.

Anyone have any ideas what is going on? I haven't been able to get any answers at my new job because everyone is so busy. Thank you in advance for any insight you can give.

Files starting with a period won't show up in ls unless you do ls -a . They're not "hidden" so much as omitted for brevity, since .filename's are often per-user configs and login settings which you aren't looking for most of the time.

1 Like

Thank you Corona688. One of my questions is how come when I type , filename it executes a filename that begins with a period? Shouldn't I have to type . .filename to execute such a file?

You should. ls -l filename to see what you're actually executing.

It's also possible someone put in some strange aliases to redefine some terms. Check your profiles.

1 Like

You use the dot command:

. filename

to have the current shell execute the commands in filename in your current shell execution environment. This works as long as filename is readable by you. Since the commands in filename were executed in the current shell execution environment, any variables set while it was running will be available for you to use in subsequent commands.

You use the command:

filename

(without the . ) to run the commands in filename in a separate shell execution environment . When the commands in filename are done, that separate shell execution environment is deleted and anything that commands in filename did that did not change other files or were not written somewhere disappear. This doesn't work unless you have permission to execute filename and filename is on your search path for commands (as specified by the PATH environment variable).

But, it is also possible for a shell script to set up an environment and invoke an interactive database session. That script will not end until the interactive session is terminated by logging out of the database session.

All of the above are possible whether or not filename 's first character is a <period>. The best way to figure out what a script might do is usually to read the file and look at the manual pages for your system to figure out what the commands in that file are doing.