LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   exporting JAVA_HOME, PGDATA, etc (https://www.linuxquestions.org/questions/linux-newbie-8/exporting-java_home-pgdata-etc-421324/)

mharris45 03-03-2006 01:42 PM

exporting JAVA_HOME, PGDATA, etc
 
I'm kinda of hazy on the difference between running the following three commands:
#: JAVA_HOME=/usr/java
and
#: export JAVA_HOME=/usr/java
and
#:
PATH=/usr/java/:$PATH

Could somebody help clear this up please?

JoseVilla 03-03-2006 11:32 PM

What you are doing in the three commands is setting environment variables for the shell (the command interpreter) you are working with. With the BASH shell "JAVA_HOME=/usr/java" and "export JAVA_HOME=/usr/java" are equivalent. "PATH=/usr/java/:$PATH" ads the path "/usr/java/" at the beginning of the PATH variable. It is as simple as that.

mharris45 03-06-2006 09:49 AM

thank you very much. That really clears that up.

JoseVilla 03-06-2006 06:35 PM

You are welcome.
Keep asking...a good way to learn.

docalton 03-06-2006 07:25 PM

Actually, they are not quite the same. When a script assigns a variable it is generally considered a local variable. If you export that variable it allows sub shells access to that variable.

For instance if you create 2 scripts, the first one assigns 2 variables (say v1 and v2) but only exports v2, you then call the second script from the first, the second script will know nothing about v1 but will know about v2.

test1 script: (copy below)

# test1 environment variable script
e1="non-exported variable"
e2="exported variable"
export e2
echo "Test 1 Program Environment Variables"
echo "------------------------------------"
echo "e1 = "$e1
echo "e2 = "$e2
sh test2

test2 script: (copy below)

# test2 environment variable script
echo "Test 2 Program Environment Variables"
echo "----------------------------"
echo "e1 = "$e1
echo "e2 = "$e2
cjones@chris:~$

Output would look like this:
cjones@chris:~$ sh test1
Test 1 Program Environment Variables
------------------------------------
e1 = non-exported variable
e2 = exported variable
Test 2 Program Environment Variables
----------------------------
e1 =
e2 = exported variable

Happy computing


All times are GMT -5. The time now is 12:50 PM.